File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+
4+ public class Main {
5+ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
6+ private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
7+ private static long[][] dp;
8+ private static int N;
9+
10+ public static void main(String[] args) throws IOException {
11+ init();
12+
13+ bw.flush();
14+ bw.close();
15+ br.close();
16+ }
17+
18+ private static void init() throws IOException {
19+ while (true) {
20+ N = Integer.parseInt(br.readLine());
21+ if (N == 0) return;
22+
23+ dp = new long[N+1][N+1];
24+
25+ for (int i = 0; i <= N; i++) {
26+ dp[0][i] = 1;
27+ }
28+
29+ for (int i = 1; i <= N; i++) {
30+ for (int j = 0; j <= N; j++) {
31+
32+ if (j+1 <= N)dp[i][j] += dp[i-1][j+1];
33+
34+ if (j > 0) dp[i][j] += dp[i][j-1];
35+ }
36+ }
37+
38+ bw.write(dp[N][0] + "\n");
39+ }
40+ }
41+ }
42+ ```
You can’t perform that action at this time.
0 commit comments