HDU3336Count the string

Problem Description
It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example:
s: "abab"
The
prefixes are: "a", "ab", "aba", "abab"
For each prefix, we can count the
times it matches in s. So we can see that prefix "a" matches twice, "ab" matches
twice too, "aba" matches once, and "abab" matches once. Now you are asked to
calculate the sum of the match times for all the prefixes. For "abab", it is 2 +
2 + 1 + 1 = 6.
The answer may be very large, so output the answer mod
10007.
 
Input
The first line is a single integer T, indicating the
number of test cases.
For each case, the first line is an integer n (1 <=
n <= 200000), which is the length of string s. A line follows giving the
string s. The characters in the strings are all lower-case letters.
 
Output
For each case, output only one number: the sum of the
match times for all the prefixes of s mod 10007.
 
Sample Input
1
4
abab
 
Sample Output
6
 
Author
foreverlin@HNU
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  1711 1686 3746 1358 3341 
 
 
#include<cstdio>
#include<cstring>
#define mod 10007 using namespace std; int T,l,next[],ans,num[];
char s[]; int main() {
scanf("%d",&T);
while(T--) {
memset(num,,sizeof(num));
memset(next,,sizeof(next));
scanf("%d",&l);
scanf("%s",s);
ans=;
for(int i=,j=; i<l; i++) {
while(j&&s[i]!=s[j]) j=next[j];
if(s[i]==s[j]) ++j;
next[i+]=j;
}
for(int i=; i<=l; i++) {
num[i]+=(num[next[i]]+)%mod;
ans=(ans+num[i])%mod;
}
printf("%d\n",ans);
}
return ;
}

HDU3336Count the string的更多相关文章

  1. HDU3336-Count the string(KMP)

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

  2. HDU-3336-Count the string(扩展KMP)

    链接: https://vjudge.net/problem/HDU-3336 题意: It is well known that AekdyCoin is good at string proble ...

  3. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  4. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

  5. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  6. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

  7. js报错: Uncaught RangeError: Invalid string length

    在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...

  8. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  9. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

随机推荐

  1. Asp.Net实现JS前台带箭头的流程图方法总结!(个人笔记,信息不全)

    Asp.Net实现JS前台带箭头的流程图方法总结!(持续更新中) 一.返回前台json格式 json5 = "[{\"Id\":2259,\"Name\&quo ...

  2. Cache-control no-transform Robots Exclusion Protocol

    蜘蛛协议 <今日头条>支持蜘蛛协议(Robots Exclusion Protocol)"ToutiaoSpider",同时,我们尊重所有的网络媒体,如媒体不希望内容被 ...

  3. football statistics

    https://www.whoscored.com/Players/24328/Show/Edinson-Cavani

  4. Scikit-learn库中的数据预处理(一)

    数据标准化:当单个特征的样本取值相差甚大或明显不遵从高斯正态分布时,标准化表现的效果较差.实际操作中,经常忽略特征数据的分布形状,移除每个特征均值,划分离散特征的标准差,从而等级化,进而实现数据中心化 ...

  5. [Django基础] gunicorn启动django时静态文件的加载

    目前在用nginx+gunicorn对django进行部署 当我用gunicorn -w 4 -b 127.0.0.1:8080 myproject.wsig:application启动django时 ...

  6. JZOJ 1003 [ 东莞市选 2007 ] 拦截导弹 —— 递推

    题目:https://jzoj.net/senior/#main/show/1003 n^2 的话递推就可以啦. 代码如下: #include<iostream> #include< ...

  7. shell脚本-循环选择语句

    shell脚本-循环选择语句 过程式编程语言: 顺序执行 选择执行 循环执行 注:条件中的变量,可以在执行语句中使用,不用在加上"$". if语句 根据命令的退出状态来执行命令 单 ...

  8. poj1200Crazy Search(hash)

    题目大意   将一个字符串分成长度为N的字串.且不同的字符不会超过NC个.问总共有多少个不同的子串. /* 字符串hash O(n)枚举起点 然后O(1)查询子串hash值 然后O(n)找不一样的个数 ...

  9. js 获取URL的值

    今天碰到要在一个页面获取另外一个页面url传过来的参数,一开始很本能的想到了用 split("?")这样一步步的分解出需要的参数. 后来想了一下,肯定会有更加简单的方法的!所以在网 ...

  10. 题解报告:hdu 1232 畅通工程(并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了 ...