File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-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+ static int T ;
6+ static int [][] dp = new int [10_001 ][4 ];
7+
8+ public static void main (String [] args ) throws IOException {
9+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
10+ T = Integer . parseInt(br. readLine());
11+
12+ dp[1 ][1 ] = 1 ;
13+ dp[2 ][1 ] = 1 ;
14+ dp[2 ][2 ] = 1 ;
15+ dp[3 ][1 ] = 1 ;
16+ dp[3 ][2 ] = 1 ;
17+ dp[3 ][3 ] = 1 ;
18+
19+ for (int j = 4 ; j <= 10000 ; j++ ) {
20+ dp[j][1 ] = dp[j- 1 ][1 ];
21+ dp[j][2 ] = dp[j- 2 ][1 ] + dp[j- 2 ][2 ];
22+ dp[j][3 ] = dp[j- 3 ][1 ] + dp[j- 3 ][2 ] + dp[j- 3 ][3 ];
23+ }
24+
25+ for (int i = 0 ; i < T ; i++ ) {
26+ int n = Integer . parseInt(br. readLine());
27+ System . out. println(dp[n][1 ] + dp[n][2 ] + dp[n][3 ]);
28+ }
29+ }
30+ }
31+ ```
You can’t perform that action at this time.
0 commit comments