zoukankan      html  css  js  c++  java
  • 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
     
    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
    ",iCase,ans);
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    【C/C++】最长公共子序列(LCS)/动态规划
    【C/C++】vector 动态二维数组
    【C/C++】string的长度
    【C/C++】最长不下降子序列/动态规划
    【C/C++】最大连续子序列和/动态规划
    【C/C++】输入:连续输入,以逗号隔开
    【C/C++】链表/ListNode/数据结构
    【Matlab】abs不支持复整数
    获取正在运行的服务
    从源码的角度分析Volley加载数据的过程
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3230616.html
Copyright © 2011-2022 走看看