#include <iostream>
using namespace std;
int go(int n);
int d[1001] = { 0 };
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n; cin >> n;
cout << go(n);
return 0;
}
int go(int n) {
d[1] = 1; d[2] = 2;
if (d[n])
return d[n];
d[n] = (go(n-1) + go(n - 2))%10007;
return d[n];
}
코드 맞게 잘 짰고 결과도 잘 나오는데 왜 안풀리나 싶었는데 숫자가 너무 커져서 long long 자료형의 범위조차도 넘어가 버릴 수 있기 때문이었다.
그래서 마지막에 썼던 cout<<go(n)%10007 코드를 삭제하고 매 반복마다 %10007 연산을 해줬더니 int형으로도 충분했다.