BOJ : https://www.acmicpc.net/problem/9507

github : https://github.com/junho0956/Algorithm/blob/master/9507/9507/%EC%86%8C%EC%8A%A4.cpp

 

문제에서 0 1 2 3 4 에 대한 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
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[68= { 1,1,2,4,8, };
 
ll solve(int num) {
    
    ll& res = dp[num];
    if (res) return res;
 
    return res = solve(num - 1+ solve(num - 2+ solve(num - 3+ solve(num - 4);
}
 
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
    solve(67);
 
    int T; cin >> T;
    while (T--) {
        int n; cin >> n;
        cout << dp[n] << "\n";
    }
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 1681번 줄 세우기  (0) 2020.02.10
BOJ 4781번 사탕가게  (0) 2020.02.10
BOJ 1914번 하노이 탑  (0) 2020.02.10
BOJ 11722번 가장 긴 감소하는 부분수열  (0) 2020.02.09
BOJ 1003번 피보나치 함수  (0) 2020.02.09

+ Recent posts