Hehe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11 Accepted Submission(s): 5
Problem Description
As we all know, Fat Brother likes MeiZi every much, he always find some topic to talk with her. But as Fat Brother is so low profile that no one knows he is a rich-two-generation expect the author, MeiZi always rejects him by typing “hehe” (wqnmlgb). You have to believe that there is still some idealized person just like Fat Brother. They think that the meaning of “hehe” is just “hehe”, such like “hihi”, “haha” and so on. But indeed sometimes “hehe” may really means “hehe”. Now you are given a sentence, every “hehe” in this sentence can replace by “wqnmlgb” or just “hehe”, please calculate that how many different meaning of this sentence may be. Note that “wqnmlgb” means “我去年买了个表” in Chinese.
Input
The first line contains only one integer T, which is the number of test cases.Each test case contains a string means the given sentence. Note that the given sentence just consists of lowercase letters.
T<=100
The length of each sentence <= 10086
T<=100
The length of each sentence <= 10086
Output
For each test case, output the case number first, and then output the number of the different meaning of this sentence may be. Since this number may be quite large, you should output the answer modulo 10007.
Sample Input
4 wanshangniyoukongme womenyiqichuqukanxingxingba bulehehewohaiyoushi eheheheh
Sample Output
Case 1: 1 Case 2: 1 Case 3: 2 Case 4: 3本题只需找到hehe出现的所有情况,属于排列组合问题。可以枚举所有字符串中所有连续的最长的he对于每个hehe…串,可以这么考虑,取用第一个he开始,即转化为f[n-2],和不取第一个he取起,即转化为f[n-1],f[n]=f[n-1]+f[n-2]然后就简单了。#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int mod=10007; char str[10086+100]; int da[10086+100]; int f[5000+100]; void Fun() { int i; f[0]=1; f[1]=1; for(i=2;i<=5000+100;i++) { f[i]=f[i-1]+f[i-2]; f[i]=f[i]%mod; } /* for(i=0;i<=5000+10;i++) { if(i%10==0) printf("\n"); printf("%d ",f[i]); }*/ } int main() { int cas,i,len,tmp,tag=1; int in; cin>>cas; Fun(); while(cas--) { scanf("%s",str); len=strlen(str); in=0; tmp=0; for(i=0;i<len;) { // cout<<str[i]<<str[i+1]<<"**"; if(str[i]=='h'&&str[i+1]=='e') { i=i+2; tmp++; } else { // cout<<"&&"<<endl; if(tmp) { // cout<<tmp<<" "<<in<<endl; da[in++]=tmp; } tmp=0; i++; } } if(tmp) da[in++]=tmp; __int64 ans=1; for(i=0;i<in;i++) { ans*=f[da[i]]; ans=ans%mod; } printf("Case %d: %I64d\n",tag++,ans); /* for(i=0;i<in;i++) printf("da[%d]=%d ",i,da[i]); cout<<endl;*/ } return 0; }