HDU3336(KMP)
来源:互联网 发布:公务员工资计算软件 编辑:程序博客网 时间:2024/06/05 07:43
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e6+7;int s[maxn];//文本串char p[2000010];//匹配串int next[2000010];//匹配串的next数组void GetNext(int n){ int pLen = n; next[0] = -1; int k = -1; int j = 0; while (j < pLen)//坑点啊,模板是只求出了next[n-1],但是这题需要求next[n]。。。。。!! { //p[k]表示前缀,p[j]表示后缀 if (k == -1 || p[j] == p[k]) { ++k; ++j; next[j] = k; } else { k = next[k]; } }}int main(){ #ifdef xxz freopen("in.txt","r",stdin); #endif // xxz int Case; cin>>Case; while(Case--) { int n,m; cin>>n; cin>>p; int ans = 0; GetNext(n); for(int i = 1; i <= n; i++) { if(next[i] > 0) ans++; if(ans >= 10007) ans %= 10007; } ans += n; ans %= 10007; cout<<ans<<endl; } return 0;}
0 0
- hdu3336(KMP)
- HDU3336-KMP
- hdu3336 KMP
- hdu3336(kmp)
- HDU3336(KMP)
- hdu3336 KMP
- HDU3336------KMP+DP
- hdu3336之KMP应用
- hdu3336(KMP+DP)
- hdu3336(KMP+DP)
- hdu3336(kmp+dp)
- hdu3336 KMP应用
- 【KMP】 hdu3336 Count the string
- hdu3336 Count the string-------KMP
- hdu3336 &&hdu 4552 KMP ,SAM
- hdu3336 Count the string KMP
- [KMP][HDU3336][Count the string]
- 【hdu3336】——KMP&&dp
- question2answer(q2a)怎么给WYSIWYG Editor增加查看html源码的按钮?
- C# 字符串 相关操作
- MYSQL-执行“load data local infile”报错“The used command is not allowed with this MySQL version”
- Java面向对象编程小总结
- 获取手机中已安装apk文件信息(PackageInfo、ResolveInfo)(应用图片、应用名、包名等)
- HDU3336(KMP)
- Javascript 装载和执行
- dom4j
- 验证码源码和java.lang.IllegalStateException解决办法
- c++11特性与cocos2d-x 3.0之std::bind与std::function
- 51单片机真的过时了吗?单片机、ARM、DSP、FPGA/CPLD
- timestamp 字段的格式
- 使用MySQL自身复制来恢复binlog
- Activiti或者jbpm工作流的流程回退