KMP Hdu-3336 Count the string
来源:互联网 发布:网页禁止注入js脚本 编辑:程序博客网 时间:2024/05/21 08:58
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3336
题目意思:
求一个字符串的所有前缀出现次数的总和。
以前做的一道题目,没想到,金山的比赛居然有一模一样的题。
http://acm.hdu.edu.cn/showproblem.php?pid=4552
解题思路:
dp[i]表示以i结尾的前缀的个数。
dp[i]=dp[next[i]]+1.
代码:
#include<iostream>#include<cmath>#include<cstdio>#include<cstdlib>#include<string>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<stack>#include<list>#include<queue>#define eps 1e-6#define INF (1<<30)#define PI acos(-1.0)using namespace std;#define Maxn 220000#define mod 256int next[Maxn],dp[Maxn];char save[Maxn];int n;void getnext(){ int j=0; next[1]=0; for(int i=2;i<=n;i++) { while(j>0&&save[j+1]!=save[i]) j=next[j]; if(save[j+1]==save[i]) j++; next[i]=j; } return ;}int main(){ int t; scanf("%d",&t); while(t--) //while(scanf("%s",save+1)!=EOF) { // save[0]='k'; //n=strlen(save)-1; scanf("%d%s",&n,save+1); getnext(); int ans=0; dp[0]=0; for(int i=1;i<=n;i++) { dp[i]=(dp[next[i]]+1)%mod; ans=(ans+dp[i])%mod; } printf("%d\n",ans); } return 0;}
- hdu 3336 Count the string KMP
- KMP Hdu-3336 Count the string
- HDU 3336 Count the string(KMP 理解)
- HDU 3336 Count the string KMP
- HDU 3336 Count the string(KMP+dp)
- [HDU 3336]Count the String[kmp]
- [HDU 3336]Count the String[kmp][DP]
- HDU 3336 Count the string KMP+DP
- hdu 3336 Count the string(KMP)
- hdu 3336 Count the string KMP+DP
- HDU 3336 Count the string(KMP)
- hdu 3336 Count the string(KMP)
- hdu 3336 Count the string(KMP)
- HDU 3336 Count the string / KMP
- HDU 3336 Count the string kmp+dp
- 【HDU】3336 Count the string KMP
- hdu 3336 Count the string(KMP)
- hdu -- 3336 Count the string(KMP + dp)
- 代理模式(Proxy)
- Hashtable和Directory性能比较
- Android Map 开发之高德地图
- 适配器模式(Adapter)
- php的JSON模块编译错误
- KMP Hdu-3336 Count the string
- java this 用法
- virtualbox识别U盘的问题
- 字节那些事儿
- C++ 用libcurl库进行http通讯网络编程
- Windows 8 各个版本区别对比
- poj 1191
- jquery bind 带参数函数 自动执行
- \tutorial_code\core\discrete_fourier_transform