HDU4639:Hehe

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
 

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,表达的意思总数符合斐波那契数列

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 10090
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define rank rank1
const int mod = 10007;

int f[N],len,t,cas=1;
char str[N];

int main()
{
    int i,j,k,ans;
    f[0] = 1;
    f[1] = 1;
    for(i = 2;i<N;i++)
    {
        f[i] = (f[i-1]+f[i-2])%mod;
    }
    scanf("%d",&t);
    while(t--)
    {
        ans = 0;
        int cnt = 0;
        scanf("%s",str);
        len = strlen(str);
        str[len++] = '#';
        str[len] = '\0';
        for(i = 1;i<=len;i++)
        {
            if(str[i]=='e'&&str[i-1]=='h')
            {
                cnt++;
                i++;
            }
            else
            {
                if(ans==0)
                {
                    ans = f[cnt];
                }
                else
                {
                    ans = (ans*f[cnt])%mod;
                }
                cnt = 0;
            }
        }
        printf("Case %d: %d\n",cas++,ans);
    }

    return 0;
}


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页