|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include<cstdio>
int dp[1001];
int main(void)
{
int n,ans;
scanf("%d", &n);
dp[1]=1;
dp[2]=2;
for(int i=3; i<=n; i++){
dp[i]=dp[i-1]+dp[i-2];
dp[i]%=10007;
}
printf("%d", dp[n]);
return 0;
}
|
cs |
|
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
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int num = 10007;
int[] arr = new int[n+1];
arr[1]=1;
if(n>=2) arr[2]=2;
if(n>=3) {
for(int i=3; i<=n; i++){
arr[i] = arr[i-1]+arr[i-2];
arr[i] %= num;
}
}
System.out.println(arr[n]);
}
}
|
cs |
'백준 2 > DP' 카테고리의 다른 글
| [백준 10844] 쉬운 계단 수 (0) | 2020.12.07 |
|---|---|
| [백준 1932] 정수 삼각형 (C++/Java) (0) | 2020.12.07 |
| [백준 11727] 2xN 타일링 2 (0) | 2020.12.07 |
| [백준 2579] 계단 오르기 (C++/Java) (0) | 2020.12.07 |
| [백준 1463] 1로 만들기 (C++/Java) (0) | 2020.12.07 |