File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author : Saurabh Kumar
3+ Problem Link :https://cses.fi/problemset/task/1633
4+ */
5+
6+ import java .util .Arrays ;
7+ import java .util .Scanner ;
8+
9+ public class DiceCombinations {
10+ static long MOD = 1000000007 ;
11+ static long [] dp = new long [10000007 ];
12+ public static void main (String [] args ) {
13+ Scanner sc = new Scanner (System .in );
14+ int n = sc .nextInt ();
15+ Arrays .fill (dp , -1 );
16+ System .out .println (solveTab (n ));
17+ }
18+ // TLE ::)
19+ public static long solveRec (int n ) {
20+ //Base Case ::
21+ if (n == 0 )
22+ return 1 ;
23+ if (dp [n ] != -1 ) {
24+ return dp [n ];
25+ }
26+ long ans = 0 ;
27+ for (int i = 1 ; i <= Math .min (n , 6 ); i ++) {
28+ ans = (ans + solveRec (n - i )) % MOD ;
29+ }
30+ return dp [n ] = ans ;
31+ }
32+
33+ public static long solveTab (int n ) {
34+ long [] dp = new long [n + 1 ];
35+
36+ dp [0 ] = 1 ;
37+ for (int i = 1 ; i <=n ; i ++) {
38+ for (int j = 0 ; j <= Math .min (i ,6 ); j ++) {
39+ dp [i ] += dp [i - j ];
40+ dp [i ] %= MOD ;
41+ }
42+ }
43+ return dp [n ];
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments