题意:
一个字符串,“hehe”可以由“wqnmlgb”来代替,所以问这个字符串有多少种解法。
题解:
dp[i]表示1~i+4这一段有多少种理解,所以如果str[i]="hehe.....",那么dp[i]+=i-4>=0?dp[i-4]:1。
//Time:0ms
//Memory:304KB
//Length:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define MAXN 20010
#define MOD 10007
using namespace std;
char str[MAXN];
int dp[MAXN];
int cmp(char s1[],char *s2,int len)
{
for(int i=0;i<len;++i)
if(s1[i]!=s2[i])
return false;
return true;
}
int main()
{
//freopen("/home/moor/Code/input","r",stdin);
int ncase,cnt;
scanf("%d",&ncase);
for(int h=1;h<=ncase;++h)
{
cnt=0;
scanf("%s",str);
for(int i=0;str[i+3];++i)
{
dp[i]=i?dp[i-1]:1;
if(cmp(&str[i],"hehe",4))
dp[i]+=i-4>=0?dp[i-4]:1;
dp[i]%=MOD;
cnt=dp[i];
}
printf("Case %d: %d\n",h,cnt);
}
return 0;
}