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

思路: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. (9)C#连mysql

    1官网下载 dll 2. using MySql.Data.MySqlClient; 3. <add key="con_MES" value="server=192 ...

  2. JDBC 数据库连接 Java操作数据库 jdbc快速入门

    JDBC基本概念 Java DataBase Connectivity 数据库连接 java操作数据库 本质上(sun公司的程序员)定义的一套操作关系型数据库的规则 既接口  更新内容之前 代码 pa ...

  3. 【c专家编程】分析c语言的声明

    联合: 在结构中,每个成员依次存储,而在联合中,所有成员都从偏移地址零开始存储,联合一般被用来节省空间,用法和struct相同. union bits32_tag { int whole; // 一个 ...

  4. IntelliJ IDEA 默认需要进行maven的设置

    IntelliJ IDEA 默认需要进行maven的设置 需要指定maven的地址,指定settings.xml的地址: 可以默认的在user/.m2/下面放一个settings.xml文件: 学习: ...

  5. 【数据库摘要】6_Sql_Inner_Join

    INNER JOIN 操作符 INNER JOIN keyword在表中存在至少一个匹配时返回行. SQL INNER JOIN 语法 SELECT column_name(s) FROM table ...

  6. 生成可重集的排序 (白书P184)

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

  7. 走入asp.net mvc不归路:[4]说说Action有哪些常见成员

    一个控制器中,功能最终会落实到一个个Action中实现,最常见的是增删查改操作.这些Action是一个个的方法,一般返回值是ActionResult,并且是public 方法,可以带参数,可以添加元标 ...

  8. 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的返回值自动进行各种序列化处理(序列化为 ...

  9. Android NDK JNI WARNING: illegal start byte 0x

    今天攻克了JNI WARNING: illegal start byte 0x81这个问题. 问题出现的现象是通过jni调用加密方法,调用之后返回密文内容,结果就出现这个问题. 在国外查找一段时间之后 ...

  10. 设计模式学习笔记——Chain of Responsibility职责链模式

    重点在链.一条链,如果本节点处理不了,则传递给下一个节点处理. 关键是如何传给下一个节点? 主要是由本节点决定传给哪一个节点. public class Client { public static ...