Last active
March 29, 2020 15:51
-
-
Save dalcon10028/3ffc91f7fb4c0abe1c9912727c3dafad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int n = sc.nextInt(); | |
| long[][] num = new long[n+2][10]; | |
| for (int i=1; i<=9; i++) { | |
| num[1][i] = 1; | |
| if (i==9) num[2][i] = 1; | |
| else num[2][i] =2; | |
| } | |
| for (int i=3; i<=n; i++) { | |
| for (int j=1; j<=9; j++) { | |
| if (j==1) num[i][j] = ( num[i-2][j] + num[i-1][j+1] )%1000000000; | |
| else if (j==9) num[i][j] = ( num[i-1][j-1] )%1000000000; | |
| else num[i][j] = ( num[i-1][j-1] + num[i-1][j+1] )%1000000000; | |
| } | |
| } | |
| System.out.print(Arrays.stream(num[n]).sum()%1000000000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment