pku2033 Alphacode (动态规划)

 简单DP,

 

#include <iostream> #include <string.h> using namespace std; char str[10000]; int dp[10000]; int main() { char ch1, ch2; int len, i; while (cin>>str && str[0]!='0') { memset(dp, 0, sizeof(dp)); dp[0] = 1; len = strlen(str); for (i=0; i<len; i++) { ch1 = str[i]; if (ch1>='1' && ch1<='9') dp[i+1] += dp[i]; if (i+1>=len) continue; ch2 = str[i+1]; if (ch1=='1' || (ch1=='2' && ch2>='0' && ch2<='6')) dp[i+2] += dp[i]; } cout << dp[len] << endl; } return 0; }

你可能感兴趣的:(pku2033 Alphacode (动态规划))