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+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ static long [][] dp = new long [31 ][31 ];
8+
9+ public static void main (String [] args ) throws IOException {
10+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ StringBuilder sb = new StringBuilder ();
12+
13+ while (true ) {
14+ int n = Integer . parseInt(br. readLine());
15+ if (n == 0 ) {
16+ break ;
17+ }
18+ sb. append(countPills(n, 0 )). append(" \n " );
19+ }
20+ System . out. print(sb);
21+ }
22+
23+ static long countPills (int w , int h ) {
24+ if (dp[w][h] != 0 ) {
25+ return dp[w][h];
26+ }
27+
28+ if (w == 0 ) {
29+ return 1 ;
30+ }
31+
32+ long result = countPills(w - 1 , h + 1 );
33+
34+ if (h > 0 ) {
35+ result += countPills(w, h - 1 );
36+ }
37+
38+ dp[w][h] = result;
39+ return result;
40+ }
41+ }
42+ ```
You can’t perform that action at this time.
0 commit comments