HDU 4639 Hehe (2013多校4 1008 水题)

Hehe

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

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  

 

Recommend zhuyuanchen520  

 

很水

 1 /*
 2  *  Author:kuangbin
 3  *  1008.cpp
 4  */
 5 
 6 #include <stdio.h>
 7 #include <algorithm>
 8 #include <string.h>
 9 #include <iostream>
10 #include <map>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <string>
15 #include <math.h>
16 using namespace std;
17 const int MOD = 10007;
18 int dp[10000];
19 void init()
20 {
21     dp[0] = 1;
22     dp[1] = 1;
23     dp[2] = 2;
24     for(int i = 3;i < 10000;i++)
25         dp[i] = (dp[i-1] + dp[i-2])%MOD;
26 }
27 
28 char str[20000];
29 
30 int main()
31 {
32     //freopen("in.txt","r",stdin);
33     //freopen("out.txt","w",stdout);
34     int T;
35     scanf("%d",&T);
36     int iCase = 0;
37     init();
38     while(T--)
39     {
40         iCase ++;
41         scanf("%s",str);
42         int ans = 1;
43         int len = strlen(str);
44         for(int i = 0; i < len;i++)
45         {
46             if(str[i] == 'h')
47             {
48                 int cnt = 0;
49                 for(int j = i ; j+1 <len;j+=2)
50                 {
51                     if(str[j]!='h'||str[j+1]!='e')break;
52                     cnt++;
53                 }
54                 ans = ans*dp[cnt]%MOD;
55                 if(cnt > 0)
56                 {
57                     i += cnt*2;
58                     i--;
59                 }
60             }
61         }
62         printf("Case %d: %d\n",iCase,ans);
63     }
64     return 0;
65 }

 

 

 

    原文作者:算法小白
    原文地址: https://www.cnblogs.com/kuangbin/p/3230616.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞