#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int dp1 = 1, dp2 = 2;
for (int i = 3; i <= n; ++i) {
int temp = dp1 + dp2;
temp %= 15746;
dp1 = dp2;
dp2 = temp;
}
if (n == 1)
cout << 1;
else
cout << dp2;
return 0;
}
DP문제
굳이 배열을 선언하지 않아도 된다.
https://www.acmicpc.net/problem/1904
'알고리즘 공부' 카테고리의 다른 글
백준 12904번 A와 B C++ (0) | 2024.11.15 |
---|---|
백준 7569번 토마토 C++ (1) | 2024.11.13 |
백준 9251번 LCS C++ (0) | 2024.10.31 |
백준 1987번 알파벳 C++ DFS (0) | 2024.10.30 |
백준 2110번 공유기 설치 C++ (0) | 2024.10.29 |