博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Count the string
阅读量:5062 次
发布时间:2019-06-12

本文共 2034 字,大约阅读时间需要 6 分钟。

Count the string

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 26   Accepted Submission(s) : 13
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
HDOJ Monthly Contest – 2010.03.06
 
t这一题目纯粹的KMP字符匹配,第一行输入T组测试样例。然后输入N,表示要输入一个长度为N的字符串。对于该字符串,把该字符串的一次分
解成1,  2,3...N长度的子串,然后拿去和主串匹配。把每一次能够匹配的次数累加起来,就是所要求的的答案、
1 #include 
2 #include
3 #include
4 char S[2000050],t[200005]; 5 int Len_S,Len_t,num[200005]; 6 void getNext(char p[],int next[]) 7 { 8 int j,k,L; 9 next[0]=-1;10 j=0;11 k=-1;12 while(j
View Code

 模板更新(2016.4.20):

1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 int Len; 7 void getNext(char p[],int next[],int Len_t) 8 { 9 int i=0,j=-1;10 next[0]=-1;11 while(i
View Code

 

 

转载于:https://www.cnblogs.com/Wurq/articles/3888628.html

你可能感兴趣的文章
dbutils开源项目用法
查看>>
JSP获取当前日期时间
查看>>
undefined reference to `_sbrk', `_write', `_lseek', `_read'
查看>>
基于zuul 实现API 网关
查看>>
定义自己的布局RelativeLayout 绘制网格线
查看>>
redis
查看>>
Ubuntu13.04 安装 chrome
查看>>
WampServer phpadmin apache You don't have permission to access
查看>>
解决sonarQube 'Unknown': sonar.projectKey
查看>>
java基础的第二轮快速学习!day02
查看>>
功能测试用例编写
查看>>
【笔记】给自己的博客侧栏添加小时钟
查看>>
ASPX页面弹窗的方法---javascript
查看>>
JavaScript和快速响应的用户界面
查看>>
深入浅出的排序算法-选择排序
查看>>
delphi -----(去掉窗口最大化,最小化、关闭),主窗口,和子窗口之间的设置
查看>>
一个小的手机答题网页【1. 需求及数据库设计】
查看>>
IOS 音频的 使用说明
查看>>
SQL Prompt Snippet Manager 妙用
查看>>
c# 学习心得(函数方法类)
查看>>