BOJ : https://www.acmicpc.net/problem/15988
github : https://github.com/junho0956/Algorithm/blob/master/15988/15988/%EC%86%8C%EC%8A%A4.cpp
9095번 문제에서 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
|
#include <iostream>
using namespace std;
#define MOD 1000000009
typedef long long ll;
ll dp[1000002];
ll dfs(int num) {
if (num < 0) return 0;
if (num == 0) return 1;
ll& res = dp[num];
if (res) return res;
for (int i = 1; i <= 3; i++)
res += dfs(num - i) % MOD;
return res;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while (T--) {
int n; cin >> n;
cout << dfs(n) % MOD << "\n";
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
| BOJ 15990번 1, 2, 3 더하기 5 (0) | 2020.02.18 |
|---|---|
| BOJ 15989번 1, 2, 3 더하기 4 (0) | 2020.02.18 |
| BOJ 12101번 1, 2, 3 더하기2 (0) | 2020.02.18 |
| BOJ 11403번 경로 찾기 (0) | 2020.02.17 |
| BOJ 11046번 팰린드롬?? (0) | 2020.02.16 |