hdu3336
来源:互联网 发布:realtek mac 驱动 编辑:程序博客网 时间:2024/06/08 03:12
next 数组
#include <cstdio>#include <cstring>#include <iostream>#include <time.h>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;int const MOD = 10007;int const MAXN = 200010;char s[MAXN];int next[MAXN],dp[MAXN];inline void Get_Next(int n){ memset(next,0,sizeof(next)); for(int i = 1;i < n;i++){ int j = next[i]; while(j && s[i] != s[j]) j = next[j]; if(s[i] == s[j]) next[i + 1] = j + 1; else next[i + 1] = 0; }}int main(){ int T; while(~scanf("%d",&T)){ while(T--){ int n; scanf("%d",&n); scanf("%s",s); Get_Next(n); for(int i = 0;i < n;i++){ dp[i] = 1; } dp[0] = 0; int sum = 0; for(int i = 1;i <= n;i++){ dp[i] = dp[next[i]] + 1; sum = (sum + dp[i]) % MOD; } printf("%d\n",sum); } } return 0;}
0 0
- hdu3336
- hdu3336
- hdu3336
- hdu3336
- hdu3336(KMP)
- HDU3336-KMP
- hdu3336 KMP
- hdu3336(kmp)
- HDU3336(KMP)
- hdu3336 KMP
- hdu3336 Count the string
- hdu3336 Count the string
- HDU3336:Count the string
- hdu3336-Count the string
- HDU3336------KMP+DP
- hdu3336之KMP应用
- hdu3336 Count the string
- hdu3336(KMP+DP)
- yum [Errno 256] No more mirrors to try 解决方法
- 【DP】UVA 10131 Is Bigger Smarter? LIS
- python3.3中urllib.request.open问题
- SimpleDateFormat的parse()与format()
- python操作mysql数据库
- hdu3336
- android activity与fragment的生命周期详细研究
- webdev.dev 已停止工作解决办法
- inline-block元素的空白间距解决方法
- 字符串排序
- Linux执行.sh文件,提示No such file or directory的问题
- 事件与委托 (本质)
- WebView与js的交互
- 打印日历(java)