题意:统计前缀在串中出现的次数

思路:next数组,递推

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std; #define MaxSize 200005
#define Mod 10007 char str[MaxSize];
int _next[MaxSize];
int dp[MaxSize];
int len; void GetNext(char t[]){//求next数组
int j,k;//,len;
j=;
k=-;
_next[]=-;
//len=strlen(t);
while(j<len){
if(k==-||t[j]==t[k]){
++j;
++k;
_next[j]=k;//此句可由优化替代
/*优化(仅保证求KMPIndex时可用。谨慎使用。)
if(t[j]!=t[k])next[j]=k;
else next[j]=next[k];
*/
}
else k=_next[k];
}
} int main(){
int t,i,ans;
scanf("%d",&t);
while(t--){
scanf("%d%s",&len,str);
GetNext(str);//求子串的next数组
dp[]=;
ans=;
for(i=;i<=len;++i){
dp[i]=dp[_next[i]]+;
dp[i]%=Mod;
ans+=dp[i];
ans%=Mod;
}
printf("%d\n",ans);
}
return ;
}

hdu 3336 Count the string(next数组)的更多相关文章

  1. 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) ...

  2. HDU 3336 Count the string(next数组运用)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 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 ...

  4. hdu 3336:Count the string(数据结构,串,KMP算法)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 3336 Count the string 查找匹配字符串

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  7. HDU 3336 Count the string KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...

  8. 【HDU 3336 Count the string】

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. HDU 3336——Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

随机推荐

  1. 使用Reachability检测网格

    
#pragma mark - 网络连接检查 - (void) currentReach { // 网络检测 Reachability *curReach = [Reachability reacha ...

  2. SSH: Transferred 0 file(s) 解决

    Jenkins搭建过程中,使用 Publish Over SSH 插件.发生 SSH: Transferred 0 file(s). 百度.google了几个小时,终于找到答案,特此记录. 配置如下: ...

  3. numpy数组之读写文件

    目录 通过 numpy 读写 txt 或 csv 文件 通过 numpy 读写 npy 或 npz 文件 读写 npy 文件 读写 npz 文件 通过 h5py 读写 hdf5 文件 简单读取 通过切 ...

  4. profile, bashrc, source, setup.*sh

    一. source: 命令是使该文件立刻执行,这样刚才做的修改就可以立即生效了,否则要重新启动系统修改才能生效.(执行其后命令使之立即生效,不用重启) 二.bashrc: 1.linux系统:/etc ...

  5. JVM内存分为哪几部分?各个部分的作用是什么?

    JVM内存分为哪几部分?各个部分的作用是什么?   1. Java虚拟机内存的五大区域 Java的运行离不开Java虚拟机的支持,今天我就跟大家探讨一下Java虚拟机的一些基础知识. JVM内存区域分 ...

  6. sourcetree帮助文档

    Overview SourceTree可以在bookmarks界面跟踪所有的git和mercurial项目.可以概览工程中是否有需要提交的文件等.添加新的bookmark很简单,可以通过两种方式,通过 ...

  7. 【java】java 中 byte[]、File、InputStream 互相转换

    ========================================================================= 使用过程中,一定要注意close()掉各个读写流!! ...

  8. 如何在List集合中去重

    众所周知List集合中的元素是有序的,但是List中的元素同样是可以重复的,那么我们应该怎么在List集合中去重呢? 方法一: 对于方法一而言,这也许是一个小窍门.利用的是Set集合中不允许出现重复的 ...

  9. androidproject有红色叹号的解决方式

    首先,查看SDK版本号,一般有两处.第一处是project.properties文件里的target=android-?改动成自己工程相应的SDK版本号.第二处是manifest文件里, androi ...

  10. C#语言循环语句for嵌套