hdu3366 Count the string
考虑dp[i]代表前缀s[1...i]出现的次数,必定有dp[nxt[i]] += dp[i]
倒着推就是了
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int T, n, nxt[200005], dp[200005], ans;
const int mod=10007;
char a[200005];
void mknxt(){
int k=0;
for(int i=2; i<=n; i++){
while(k && a[i]!=a[k+1]) k = nxt[k];
if(a[i]==a[k+1]) nxt[i] = ++k;
}
}
int main(){
cin>>T;
while(T--){
ans = 0;
scanf("%d", &n);
scanf("%s", a+1);
memset(nxt, 0, sizeof(nxt));
for(int i=1; i<=n; i++) dp[i] = 1;
mknxt();
for(int i=n; i>=1; i--)
dp[nxt[i]] = (dp[nxt[i]] + dp[i]) % mod;
for(int i=1; i<=n; i++)
ans = (ans + dp[i]) % mod;
printf("%d\n", ans);
}
return 0;
}
hdu3366 Count the string的更多相关文章
- Count the string[HDU3336]
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDUOJ------3336 Count the string(kmp)
D - Count the string Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- hdu 3336 Count the string KMP+DP优化
Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...
- Count the string -- HDOJ 3336
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdoj 3336 Count the string【kmp算法求前缀在原字符串中出现总次数】
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3336 Count the string(next数组运用)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- (KMP)Count the string -- hdu -- 3336
http://acm.hdu.edu.cn/showproblem.php?pid=3336 Count the string Time Limit: 2000/1000 MS (Java/Other ...
- HDU 3336 Count the string 查找匹配字符串
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- smarty基本用法
简介: 1.smarty语法:它是php的一种模板引擎 它的设计特点是:业务逻辑与显示逻辑分离 Smarty的标签都是使用定界符{ }括起来注释:{* 我是Smarty的注释内容 *} <u ...
- 常用的Homebrew命令
一些常用的Homebrew命令: 更新:brew update 安装包信息检索:brew info 安装包搜索:brew search foo 安装包列表:brew list 过时信息:brew ou ...
- uLua学习之数据交互(三)
前言 在上节中,大概谈了一下如何在lua脚本中调用unity3d中的方法来创建游戏物体,这只是很小的一个方面,uLua的优势在于对unity3d中C#语言的扩展和定制.那么如何扩展和定制呢?其中的数据 ...
- WebChromeClient
WebChromeClient 辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等 onCloseWindow(关闭WebView) onCreateWindow ...
- Nodejs入门边读边想边记(-)
Node入门>>一本全面的Node.js教程网站地址:http://www.nodebeginner.org/index-zh-cn.html 本文记录我在阅读上面这个网站的过程中得到的一 ...
- Win10 应用商店管理应用
在企业日常办公中,对 Windows 10 应用商店软件不需要,希望办公系统干净一些.企业运维中,我们可以使用组策略来管理Windows 10 微软Store应用程序.可以根据组织的要求进行配置,多项 ...
- No module named 'revoscalepy'问题解决
SqlServer2017开始支持Python,前段时间体验了下,按照微软的入门例子操作的:https://microsoft.github.io/sql-ml-tutorials/python/re ...
- pta编程题19 Saving James Bond 2
其它pta数据结构编程题请参见:pta 题目 和简单版本不同的是,简单版本只需判断能否到达岸边,而这个版本要求求出最少跳数的路径. 简单版本用dfs实现,而这道题用BFS实现. 注意: 岛半径为7.5 ...
- 设置RichTextBox控件的文本的对齐方式
实现效果: 知识运用: RichTextBox控件的SelectionAlignment属性 //获取或设置在当前选择或插入点的对齐方式 public HorizontalAlignment Sele ...
- 通过jQuery遍历div里面的checkbox
遍历: $('#queryUser2 input[type="checkbox"]:checked').each( function () { a = a + $(this).va ...