HDU4639 Hehe【水题】

Hehe

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2349 Accepted Submission(s): 1081

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

Source
2013 Multi-University Training Contest 4

问题链接HDU4639 Hehe
问题简述
    一个hehe表示2种意思,给定一个字符串能够表示多少意思。
问题分析
    连续的若干个he表达的意思总数符合斐波那契数列。打表计算是需要的。
    没有hehe的句子只有1种意思。一个句子有若干个连续的he,那么分段算出he…he能表达多少种意思,然后求积区余。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* HDU4639 Hehe */

#include <stdio.h>
#include <string.h>

#define MOD 10007
#define N 10086
int fib[N / 2 + 1];
char s[N + 1];

void setfib()
{
    int i;
    fib[0] = 1;
    fib[1] = 1;
    for(i = 2; i <= N / 2; i++)
        fib[i] = (fib[i - 2] + fib[i - 1]) % MOD;
}

int main()
{
    setfib();

    int t, k, i;
    scanf("%d", &t);
    for(k = 1; k <= t; k++) {
        scanf("%s", s);
        int sum=1, cnt=0, len = strlen(s) - 1;
        for(i = 0; i <= len; i++)
            if(i < len && s[i] == 'h' && s[i + 1] == 'e') {
                while(s[i] == 'h' && s[i + 1] == 'e')
                    cnt++, i += 2;
                sum = (sum * fib[cnt]) % MOD;
                cnt = 0;
            }
        printf("Case %d: %d\n", k, sum);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10223335.html