HDU3336-Count the string-KMP(next数组理解)
来源:互联网 发布:audition软件下载 编辑:程序博客网 时间:2024/06/05 00:28
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336
好吧,对next数组还是没有理解到位,感觉有很多的出发点。还需要去更深的理解。
#include<iostream>#include<string>using namespace std;string str;int n,Next[200005];void get_next(){ int i=0,j=-1; Next[0]=-1; while(i<n){ if(j==-1||str[i]==str[j]){ i++,j++; Next[i]=j; // 没有判断。 }else{ j=Next[j]; } }}int main(){ int t; cin.sync_with_stdio(false); cin>>t; while(t--){ cin>>n>>str; int sum=0; get_next(); //for(int i=0;i<=n;i++) cout<<Next[i]<< ' ';cout<<endl; for(int i=1;i<=n;i++){ int j=i; while(j){ sum=(sum+1)%10007; j=Next[j]; } } cout<<sum<<endl; } return 0;}
0 0
- HDU3336-Count the string-KMP(next数组理解)
- hdu3336 Count the string(next数组)
- HDU3336 Count the string(KMP,next的性质)
- 【KMP】 hdu3336 Count the string
- hdu3336 Count the string-------KMP
- hdu3336 Count the string KMP
- [KMP][HDU3336][Count the string]
- HDU3336 Count the string (KMP)
- Hdu 3336 Count the string[KMP next数组的理解]
- Count the string kmp next数组应用
- HDU3336-Count the string(KMP)
- hdu3336 Count the string KMP+dp
- hdu3336 Count the string(kmp+dp)
- hdu3336 Count the string(KMP应用)
- HDU3336 Count the string(KMP)
- hdu3336 Count the string--KMP+DP
- HDU3336 Count the string KMP+递推
- hdu3336 Count the string (KMP)
- java内存机制
- GTK+图形化应用程序开发学习笔记(十三)—微调构件
- JavaScript练习(三)简单的轮播器原理代码
- python模块的发布
- 文件的基本编译
- HDU3336-Count the string-KMP(next数组理解)
- 一种在线客服均衡分配的方法及装置
- 多态
- jquery中attr和prop的区别分析——源于checked属性的思考
- 失败的开始
- GTK+图形化应用程序开发学习笔记(十四)—组合框构件
- [Cocos2d塔防游戏开发]Cocos2dx-3.X完成塔防游戏《王国保卫战》--防御塔(六)之兵营塔
- Spring+Mybatis配置多数据源
- super 和 this 关键字的比较+调用构造器(this)+动态绑定