이 문제는 동적계획법으로
첫 번째 타일이 세로로 있을 때(n-1)랑 2개의 타일이 가로로 되어있을 때(n-2)의 경우의 수를 합하는 것과 같다.
이는 피보나치 수열과 같으므로 같은 방법으로 풀면 된다.
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 | #include <iostream> #include <cstdio> #pragma warning(disable : 4996) using namespace std; unsigned long long result[1001]; unsigned long long fibonacci(int n) { if (n == 1) return result[n] = 1; if (n == 2) return result[n] = 2; if (result[n] > 0) return result[n]; else return result[n] = (fibonacci(n - 1) + fibonacci(n - 2))%10007; } int main() { int input; cin >> input; cout << fibonacci(input); return 0; } | cs |
'Algorithm Problems > BOJ' 카테고리의 다른 글
[11053번] 가장 긴 증가하는 수열 - LIS & DP[C++] (0) | 2017.03.06 |
---|---|
[13699번] 점화식 - Dynamic Programming 동적계획법[C++] (0) | 2017.02.20 |
[1010번] 다리 놓기 - Dynamic Programming 동적 계획법[C++] (0) | 2017.02.20 |
[1730번] 판화 - 비트마스크, 배열[C++] (0) | 2017.02.13 |
[11657번] Time Machine 타임머신 - Bellman-Ford Algorithm[C++]☆ (0) | 2017.01.17 |