#include <iostream> #include <string> using namespace std; #define mod 1000000 int main() { char code[5001]; int length; string str; cin >> code; str = code; length = str.size(); int dp[5001][2]={0};
dp[0][0] = 1; dp[1][0] = 1; if(str[0]=='1' || (str[0]=='2' && str[1] <'7')) { dp[1][0] = 1; dp[1][1] = 1; } cout << "i = 1" << ", dp[" << 1 << "] : " << dp[0][0]+dp[0][1]<<endl; cout << "i = 2" << ", dp[" << 2 << "] : " << dp[1][0]+dp[1][1]<<endl; for(int i=2; i<length; i++) { if(str[0]=='1' || (str[0]=='2' && str[1] <'7')) { dp[i][0] = dp[i-1][0]%mod+dp[i-1][1]%mod; dp[i][1] = dp[i-2][0]%mod+dp[i-2][1]%mod; } else { dp[i][0] = dp[i-1][0]%mod+dp[i-1][1]%mod; } cout << "i = " << i+1 << ", dp[" << i+1 << "] : " << dp[i][0]+dp[i][1]<<endl; } cout << dp[length-1][0]%mod+dp[length-1][1]%mod <<endl; system("pause"); } |
왜 틀린걸까?
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
171019_1699_제곱수의 합 (0) | 2017.10.19 |
---|---|
171018_p를 출력하는 프로그램 p (0) | 2017.10.18 |
171016_6359_만취한 상범 (0) | 2017.10.16 |
171014_1309_동물원 (0) | 2017.10.14 |
171013_1005_ACM Craft (0) | 2017.10.13 |