[Link] https://www.acmicpc.net/problem/2482
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader br;
static StringBuilder sb = new StringBuilder();
static int div = 1000000003;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
int n = toi(br.readLine()), k = toi(br.readLine());
int[][] dp = new int[n + 1][n + 1];
for(int[] ar: dp) Arrays.fill(ar, -1);
int ans = (dfs(dp, n - 3, k - 1) + dfs(dp, n - 1, k)) % div;
print(ans);
}
static int dfs(int[][] dp, int len, int num) {
if(num > (len + 1) / 2) return 0;
if(num == 0) return 1;
if(num == 1) return len;
if(dp[len][num] != -1) return dp[len][num];
return dp[len][num] = (dfs(dp, len - 2, num - 1) + dfs(dp, len - 1, num)) % div;
}
static int toi(String s) { return Integer.parseInt(s); }
static String[] getLine() throws IOException { return br.readLine().split(" "); }
static int[] getArr() throws IOException { return Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); }
static <T> void print(T s) { System.out.print(s); }
static <T> void println(T s) { System.out.println(s); }
}