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>
#define N 10100
#define M 5050
#define MOD 10007
using namespace std;
int main ()
{
int t, i, j = 1;
int len, sum, num;
int a[M];
char b[N];
a[0] = a[1] = 1;
for (i=2; i<M; i++)
a[i] = (a[i-1] + a[i-2]) % MOD;
scanf ("%d", &t);
while (t --)
{
scanf ("%s", b);
num = 0;
sum = 1;
len = strlen (b);
for (i=0; i<len-1; i++)
if (b[i]==‘h‘ && b[i+1]==‘e‘)
num ++, i++;
else
{
sum = sum * a[num] % MOD;
num = 0;
}
if ( num )
sum = sum * a[num] % MOD;
printf ("Case %d: %d\n", j++, sum);
}
return 0;
}

hdu 4639 Hehe

时间: 2024-07-28 12:31:36

hdu 4639 Hehe的相关文章

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 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]

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 - 2879

HDU - 2879HeHe 题意:He[N]为[0,N−1]范围内有多少个数满足式子x2≡x (mod N),求HeHe[N]=He[1]×……×He[N] 我是通过打表发现的he[x]=2k,k为x是质因子个数,不过这是可以通过积性函数证明的. 关于积性函数的定义: 对于正整数n的一个算术函数 f(n),若f(1)=1,且当a,b互质时,f(ab)=f(a)f(b),在数论上就称它为积性函数.若对于某积性函数 f(n) ,就算a, b不互质,也有f(ab)=f(a)f(b),则称它为完全积性

HDU 4902 (牛叉的线段树)

Nice boat Problem Description There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and c

HDU 4888 Redraw Beautiful Drawings 网络流 建图

题意: 给定n, m, k 下面n个整数 a[n] 下面m个整数 b[n] 用数字[0,k]构造一个n*m的矩阵 若有唯一解则输出这个矩阵,若有多解输出Not Unique,若无解输出Impossible 思路:网络流,,, n行当成n个点,m列当成m个点 从行-列连一条流量为k的边,然后源点-行连一条a[i]的边, 列-汇点 流量为b[i] 瞎了,该退役了 T^T #include<stdio.h> #include<string.h> #include<iostream&

HDU 4944

FSF’s game Problem Description FSF has programmed a game.In this game, players need to divide a rectangle into several same squares.The length and width of rectangles are integer, and of course the side length of squares are integer. After division,

HDU 4923 (贪心+证明)

Room and Moor Problem Description PM Room defines a sequence A = {A1, A2,..., AN}, each of which is either 0 or 1. In order to beat him, programmer Moor has to construct another sequence B = {B1, B2,... , BN} of the same length, which satisfies that:

HDU 4897 Little Devil I

_(:3 ⌒?)_ 调我半天,还是记录下吧. 用轻重链可解决此题. 用轻重链的方式给点重新编号后,建两棵线段树,一棵(sumTree)用于记录路径修改,另外一棵(markTree)用于记录邻边修改的点. 然后维护下两棵树即可. 注意,markTree修改时,要在sumTree上修改第一个点和最后一个点对应的重边,若修改的顶点为连接轻链的点,则sumTree对应边不修改. #include<cstdio> #include<cstring> #include<algorithm