알고리즘 및 자료구조/문제
백준알고리즘 11057번 오르막 수
ktko
2018. 5. 10. 14:51
백준알고리즘
https://www.acmicpc.net/problem/11057
1일 때
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
2 일 때
00 |
01 |
02 |
03 |
04 |
05 |
|
|
|
|
|
11 |
12 |
13 |
14 |
15 |
|
|
|
|
|
|
22 |
23 |
24 |
25 |
|
|
|
|
|
|
|
33 |
34 |
35 |
|
|
|
|
|
|
|
|
44 |
45 |
|
|
|
|
|
|
|
|
|
55 |
|
|
|
|
이런 식으로 가게 되면 식이 나오는데
dp[i][j] += dp[i-1][j] 여기서 J를 포문을 돌려야 한다.
예를 들어 j가 5라면 dp[i-1][0] + dp[i-1][1] +dp[i-1][2] +dp[i-1][3] +dp[i-1][4] + dp[i-1][5] 가 된다.
import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); int count = Integer.parseInt(scan.nextLine().trim()); int saveArray[][] = new int[count+1][10]; for(int i=0; i < 10; i++) saveArray[1][i] = 1; for(int i=1; i <= count; i++) { for(int j=0; j < 10; j++) { for(int k=0; k <= j; k++) { saveArray[i][j] += saveArray[i-1][k]; saveArray[i][j] %= 10007; } } } int total = 0; for(int i=0; i < 10; i++) { total += saveArray[count][i]; } System.out.println(total % 10007); scan.close(); } }