HDU 5763
来源:互联网 发布:java多态的实现原理 编辑:程序博客网 时间:2024/06/12 12:22
KMP,预处理nxt,然后去文本串中匹配,f[i]表示前i个字母有多少种意思,当匹配到i成功时,说明i-len+1.....i可以表达为2种意思,所以f[i]=f[i-1]+f[i-len]。想了许久,暴露了我的sb智商
#include<cstdio>#include<cstring>#define maxl 100010#define mod 1000000007int cas,tlen,slen;int f[maxl],nxt[maxl];char t[maxl],s[maxl];void getnxt(){int j=0;nxt[1]=0;for(int i=2;i<=tlen;i++){while(j && t[j+1]!=t[i])j=nxt[j];if(t[j+1]==t[i])j++;nxt[i]=j;}}void prework(){scanf("%s%s",s+1,t+1);tlen=strlen(t+1);slen=strlen(s+1);getnxt();}void mainwork(){f[0]=1;int j=0;for(int i=1;i<=slen;i++){f[i]=f[i-1];while(j && t[j+1]!=s[i])j=nxt[j];if(t[j+1]==s[i])j++;if(j==tlen)f[i]=(f[i]+f[i-tlen])%mod;}}void print(){printf("Case #%d: %d\n",cas,f[slen]);}int main(){int tot;scanf("%d",&tot);for(cas=1;cas<=tot;cas++){prework();mainwork();print();}return 0;}
阅读全文
0 0
- HDU 5763
- HDU 5763 Another Meaning
- HDU 5763 dp+kmp
- HDU 5763 (哈希 DP)
- 解题报告:HDU 5763
- hdu 5763 kmp + dp
- HDU 5763 Another Meaning
- HDU 5763 Another Meaning
- hdu 5763 substr()
- 【HDU】5763 Another Meaning
- hdu 5763 Another Meaning
- hdu 5763(kmp + dp)
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- 如何查找MySQL中查询慢的SQL语句
- ReLU Sigmoid and Tanh(2)
- scray中的Request 不执行回调
- bzoj2038 小Z的袜子(hose) 莫队算法(不修改只查询 基础版)
- 转换java
- HDU 5763
- Ultra-QuickSort
- Hive采集数据框架flume
- 网络编程(tcp、udp)
- FireFox插件RESTClient POST请求带json数据
- LeetCode--150. Evaluate Reverse Polish Notation
- Monte Carlo方法
- Super Jumping! Jumping! Jumping!||HDU1087
- 难度较大的网络线程