작성일: 2024-01-16
문제
- 난이도: 실버1
- 알고리즘: dp
코드
#include <iostream>
#include <vector>
using namespace std;
vector<int> cache(100001, -1);
int getAvailCase(int num) {
if(num<0) return 0;
if(num==0) return 1;
if(cache[num]!=-1) return cache[num];
int ret=0;
for(int i=1; i<=3; i++) {
ret+=getAvailCase(num-i);
ret%=1000000009;
}
return cache[num]=ret;
}
int main() {
int testCase;
cin>>testCase;
for(testCase; testCase>0; testCase--) {
int input;
cin>>input;
int ret=0;
for(int mid=input%2; mid<=(input%2)+2; mid+=2) {
ret+=getAvailCase((input-mid)/2);
ret%=1000000009;
}
cout<<ret<<"\n";
}
}회고
다른 문제들과 거의 비슷했다. 한쪽만 생각하면 저절로 대칭이 되니 오히려 쉬웠던거 같다.
