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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-08 12:58:13

HDU4639:Hehe的相关文章

HDU2879 HeHe 数论积性函数

题目名字有点搓,做题时没做出来,学长他们做出了,发现跟网上题解的思路没太大区别,网上所有题解的分析也都转自同一个地方,看样子这道题目不是那么好想的,没办法按照解析画了半天,计算器按了半天,理解了,自己敲出来了,觉得值得留念,打算再刷几道这样的 转自:http://blog.csdn.net/kksleric/article/details/8096914 定义:对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时f(ab)=f(a)f(b),在数论上就称它为积性函数.若对于某积

HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)

题目 //每次for循环的时候总是会忘记最后一段,真是白痴.... //连续的he的个数 种数 //0 1 //1 1 //2 2 //3 3 //4 5 //5 8 //…… …… //斐波纳契数列 //不连续的就用相乘(组合数)好了 #include<iostream> #include<algorithm> #include<string> #include <stdio.h> #include <string.h> #include &l

hdu 4639 Hehe

大意:给你一个字符串,字符串中的hehe可以换成wqnmlgb,问有几种换发? 思路: 1.由分析不难得出连续的he出现的时候f[n]=f[n-1]+f[n-2]. 2.扫描字符串,利用上面算出的f[n]对字符串中出现的hehe进行计算即可 3.各个不连续的hehe串的f[]乘起来就得到了. 代码: #include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#defin

HDU 5084 HeHe --找规律

题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每个值).直接对每个查询做n次累加(n*m=10^8的复杂度)竟然可以水过. 官方题解给的是n^2的算法,维护一个前缀和,即sum[i][j] 表示 i+j不变的所有sum[i][j]之和. 因为 ans[x][y]就是 a[y]*a[2*n-x] + .... + a[y+n-1]*a[n-x+1]

hehe

hele 1 int vec_rotate(char *vec,int rotdist, int length) { 2 int i,j,k,times; 3 char t; 4 times = gcd(rotdist,length); 5 printf("%d\n",times); 6 for(i=0;i<times;i++) { 7 t = vec[i]; 8 j = i; 9 while(1) { 10 k = j+ rotdist; 11 if(k>=length)

python面向对象知识点疏理

面向对象技术简介 类: 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例.class 类变量:类变量在整个实例化的对象中是公用的.类变量定义在类中且在函数体之外.类变量通常不作为实例变量使用. 数据成员:类变量或者实例变量用于处理类及其实例对象的相关的数据. 方法重写:如果从父类继承的方法不能满足子类的需求,可以对其进行改写,这个过程叫方法的覆盖,也称为方法的重写. 实例变量:定义在方法中的变量,只作用于当前实例的类. 继承:即一个派生类(de

__index元方法

如果定义了一个元表 table = {a = 1} setmetatable(table, {__index = {b = 2}}) 那么如果在table中取没有定义的键,那么lua就会在__index元方法里面去找,前提是__index是一个表,她还可以是一个函数 print(table.a,table.b) ------------ 那么当__index元方法是函数会怎么样呢?lua会调用这个函数,并传入表和你写的那个键 t = setmetatable({a=1},{__index = f

URAL - 1963(几何)

不知道是不是几何题,反正就是找对称,值得注意的是,对称轴不一定过点,还可能在边上 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const double mm=1e-7; double x[10],y[10]; bool deng(double a,double

软件151 刘光星

一.下载Struts 建立web项目,给项目添加外部引用包(project-properties-Java Build Path-Add External Jars...).添加的包有:commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,commons-logging-api-1.1.jar,freemarker-2.3.16.jar,javassist-3.7.ga.jar,ognl-3.0.jar,struts2-core-2.2.1.1.ja