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) ...
 
随机推荐
- 学习笔记:MDN的Web入门
			
HTML: 要引用一个父目录的文件,加上两个点. HTML并不是真正的编程语言,它是一种用于定义内容结构的标记语言. 元素(Element):开标签.闭标签与内容相结合,便是一个完整的元素.元素可以用 ...
 - #include stdio.h(1)
			
#include <stdio.h> int main() { //************一.运算符********** //1.赋值运算符 = ; //赋值运算符表示的是将等号右边的赋 ...
 - weex 项目搭建
			
第一步:安装依赖 npm install -g weex-toolkit weex -v //查看当前weex版本 weex update weex-devtool@latest //@后标注版本后, ...
 - wow.js+animate.css——有趣的页面滚动动画
			
今天偶然间发现了一个使用特别简单的页面动画效果,还挺不错的,玩了一个上午,现在介绍一下这个滚动动画: 一.使用方法: 1.下载animate.css 2.下载wow.js 3.引用文件,像这样: &l ...
 - 巧用netsh命令实现端口转发(端口映射)不求人
			
好处:即时生效,随意修改删除,不影响其他ip映射 记事本保存为bat格式批量添加后,并查看映射: netsh interface portproxy add v4tov4 listenport=701 ...
 - C# asp.net mvc 注解验证
			
看代码,看注解,看懂了单词,没看懂意思. 今日只能专攻一下这项特性. 1.Remote 在看这个例子的时候 ,看了JsonResult 以及 JsonRequestBehavior.AllowGet解 ...
 - hiho一下 第三十八周 二分答案
			
题目链接:http://hihocoder.com/contest/hiho38/problem/1 ,挺难想的解题思路,好题. 按照提示的算法来: 我们需要找什么? 在这个题目中我们需要找的是路径最 ...
 - 3218: 字符串字符统计—C语言
			
3218: 字符串字符统计—C语言 时间限制: 1 Sec 内存限制: 128 MB提交: 270 解决: 129[提交][状态][讨论版][命题人:smallgyy] 题目描述 编写一函数,由实 ...
 - DongDong坐飞机
			
题目连接:https://ac.nowcoder.com/acm/contest/904/D 第一次研究了一下这种题型,还是比较好理解的,因为有半价次数的限制,所以要把每一中情况都写出来,dp[现在的 ...
 - double类型的小数,四舍五入保留两位小数
			
import java.math.BigDecimal; public class Kewai{ public static void main(String[] args) { double f = ...