File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+
4+ public class Main {
5+ public static void main (String [] args ) throws Exception {
6+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+
8+ long [][] dp = new long [31 ][31 ];
9+
10+ for (int h = 0 ; h <= 30 ; h++ ) {
11+ dp[0 ][h] = 1 ;
12+ }
13+
14+ for (int w = 1 ; w <= 30 ; w++ ) {
15+ for (int h = 0 ; h <= 30 ; h++ ) {
16+ long v = 0 ;
17+
18+ if (w > 0 && h < 30 ) {
19+ v += dp[w - 1 ][h + 1 ];
20+ }
21+
22+ if (h > 0 ) {
23+ v += dp[w][h - 1 ];
24+ }
25+
26+ dp[w][h] = v;
27+ }
28+ }
29+
30+ StringBuilder sb = new StringBuilder ();
31+ while (true ) {
32+ String line = br. readLine();
33+ if (line == null || line. isEmpty()) break ;
34+
35+ int n = Integer . parseInt(line);
36+ if (n == 0 ) break ;
37+
38+ sb. append(dp[n][0 ]). append(' \n ' );
39+ }
40+
41+ System . out. print(sb);
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments