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

思路: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. CF 2018 Battle of Brains GYM 102062 F

    https://codeforces.com/gym/102062/attachments/download/8213/2018-battle-of-brains-en.pdf https://cod ...

  2. vue之监听事件

    一.v-on 可以用 v-on 指令监听 DOM 事件,并在触发时运行一些 JavaScript 代码. 简写形式  用@代替 v-on: <button v-on:click="co ...

  3. AbstractQueuedSynchronizer 队列同步器源码分析

    AbstractQueuedSynchronizer 队列同步器(AQS) 队列同步器 (AQS), 是用来构建锁或其他同步组件的基础框架,它通过使用 int 变量表示同步状态,通过内置的 FIFO ...

  4. Ubuntu 16.04通过Snap安装应用程序

    16.04LTS可以说是一个不寻常的5年支持版本,同时也带来了Snap应用,并通过Snap可以安装众多的软件包.需要注意的是,Snap是一个全新的软件包架构,但是同样也比其它的软件包大很多. 简单的安 ...

  5. 《深入理解mybatis原理》 MyBatis的一级缓存实现详解 及使用注意事项

    MyBatis是一个简单,小巧但功能非常强大的ORM开源框架,它的功能强大也体现在它的缓存机制上.MyBatis提供了一级缓存.二级缓存 这两个缓存机制,能够很好地处理和维护缓存,以提高系统的性能.本 ...

  6. activiti实现的请假流程

    直接上图,还是有点复杂的

  7. JZ2440:时钟设置

    这一节的目标是对板子上的时钟有一个初步的了解.而且能通过初步设置.为我们接下来的程序做准备. 1. 板子上的基本资源: 板载晶振12M 主时钟源和 USB 时钟源都是晶振 2. 手冊中的相关项(按时钟 ...

  8. c程序设计语言第一章5

    练习1.20请编写程序d e t a b

  9. ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目

    ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml)   我们都知道在使用WebApi的时候Controller会自动将Action的返回值自动进行各种序列化处理(序列化为 ...

  10. getElementByID,getElementsByName,getElementsByTagName

    <input type="checkbox" name="hobby" id="hobby1"> 音乐 <input ty ...