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: 22Description
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; }
相关文章推荐
- 1678:A lot of dream [300分]
- Codeforces Round #260 (Div. 1) B. A Lot of Games Trie + 博弈
- ***qwb has a lot of Coins nim博弈
- A Dream of Language Communication
- CF 455B-- A Lot of Games
- CF Gym 100187B A Lot of Joy (古典概型)
- Codeforces Gym 100187 B A Lot of Joy(期望)
- A lot of Javascript tips
- hdu 4686 Arc of Dream
- 【HDOJ 4686】 Arc of Dream (矩阵快速幂)
- The Difference Between Big Data and a Lot of Data
- Save a lot of code by using NSClassFromString in Objective C
- CodeForces 456D&455B--A Lot of Games(Trie+博弈)
- HDU 4686 Arc of Dream
- A Lot of Games(Trie树 + 博弈)
- hdu4686 Arc of Dream 矩阵快速幂
- Gym 100187B - A Lot of Joy
- A Lot of Joy
- system play - qemu with a lot of system imgs (maybe I'll develop one by myself)
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 F: qwb has a lot of Coins [nim]【博弈】