it/알고리즘
백준 11057 - 오르막 수
하얀나다
2019. 9. 1. 01:43
경우의 수로 DP로 생각.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
public class Main {
static int N;
static int MOD = 10007;
static int dp[][];
static int result;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
dp = new int[N+1][10];
for(int j = 0; j<dp[0].length; j++) {
dp[0][j] = 1;
}
for (int i = 1; i <= N; i++) {
dp[i][0] = 1;
for(int j = 1; j<dp[i].length; j++) {
dp[i][j] = dp[i-1][j] + dp[i][j-1];
dp[i][j] %= MOD;
}
}
result = dp[N][dp[0].length-1];
System.out.println(result);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
처음에 mod 를 나누기 안해줘서 값크기가 int 허용값을 넘어서 틀렸음.