您的位置:首页 > 其它

1678:A lot of dream [300分]

2013-12-04 09:22 239 查看

A lot of dream [300分]

Time Limit: 1000 ms Memory Limit: 65536 KB Total Submit: 44 Accepted: 22
Description
Give you a string , calculate how many dream in it. Rules: 不能换顺序(如:drema计为0次) 可以不连续(如:dbbbbbream计为1次) 每个字母可用多次(如:ddream计为 2 次(r、e、a、m用了两次))

Input
多case ,每组数据包括一行字符串,字符串长度 len (1<=len<=100000).

Output
每组数据输出dream 的个数,结果mod 10000007;

Sample Input
drema
dbbbbbream
ddream
dreamdream

Sample Output
0
1
2
6

Hint

dreamdream 10个字母分别记为 d1、r1、e1、a1、m1、d2、r2、e2、a2、m2、

d1 r1 e1 a1 m1
d1 r1 e1 a1 m2
d1 r1 e1 a2 m2
d1 r1 e2 a2 m2
d1 r2 e2 a2 m2
d2 r2 e2 a2 m2

#include <stdio.h>
#include <string.h>
#define N 100010
char f
;
__int64 maxm,maxa,maxe,maxr,maxd;
__int64 len,i;
#define M 10000007
/*
第一感觉是想深搜,但是len最大为100000,深搜如果数据过大的话一般都会超时;
这个时候想到递推,从后往前
(因为从前往后的时候,如果当前字母为d,但是不知道后面不连续的earm字符串
有多少个,无法判断这个d可以构成多少个不连续的dream字符串,而从后往前,
则可以满足这个条件。)

*/
int main()
{
while(scanf("%s",f)!=EOF)
{
len=strlen(f);
maxm=maxa=maxe=maxr=maxd=0;
for(i=len-1;i>=0;i--)
{
if(f[i]=='m')
maxm=(maxm+1)%M;
else if(f[i]=='a')
maxa=(maxa+maxm)%M;
else if(f[i]=='e')
maxe=(maxe+maxa)%M;
else if(f[i]=='r')
maxr=(maxr+maxe)%M;
else if(f[i]=='d')
maxd=(maxd+maxr)%M;
else ;
}
printf("%I64d\n",maxd);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: