HDU3336Count the string
HDU3336Count the string
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.
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.
match times for all the prefixes of s mod 10007.
4
abab
#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的更多相关文章
- HDU3336-Count the string(KMP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU-3336-Count the string(扩展KMP)
链接: https://vjudge.net/problem/HDU-3336 题意: It is well known that AekdyCoin is good at string proble ...
- 透过WinDBG的视角看String
摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...
- JavaScript String对象
本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...
- ElasticSearch 5学习(9)——映射和分析(string类型废弃)
在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...
- [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密
string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...
- js报错: Uncaught RangeError: Invalid string length
在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed
之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...
随机推荐
- 【JAVA】两点经纬度直线距离的计算
来自谷歌地图的计算公式: 通过JAVA的Math类各种方法调用.实现上述公式 private static double EARTH_RADIUS = 6378.137;// 单位千米 /** * 角 ...
- VC中CString和WPARAM之间的相互转换
在传递自己定义消息的过程中.须要转换CString 变量. 在发送消息端使用例如以下方法: SendMessage(WM_MESSAG_MINE,0,(LPARAM)strVal.AllocSysSt ...
- 关于C语言指针的一些新认识(2)
在使用C语言编程的过程中,遇到了很多关于指针使用的小问题,这里总结一下就当做是编程的小技巧啦 Q1. 如何用printf( )输出指针 这个问题相当于如何用printf( )输出地址,答案是:用"%p ...
- Linux VM环境配置
1. 直接打 ifconfig ,显示 bash: ifconfig: command not found 打入全路径,查看IP /sbin/ifconfig 2. 主机ping不通虚拟机, ...
- mac 浏览器解决跨域问题
Chrome:命令行执行如下命令open -a Google\ Chrome --args --disable-web-security出现如下提示,说明已经开启: Safari: open -a ' ...
- CentOS6.5配置代理上网
虚拟机vmWare下装了个CentOS,第一件事是配置代理上网,因为工作环境需要使用代理上网,但发觉与uBuntu不同,根本没有什么/etc/environment. 在网上疯狂搜索,都说要配置/et ...
- WPF学习笔记:获取ListBox的选中项
有代码有J8: UI <UserControl x:Class="UnitViews.UserListUV" xmlns="http://schemas.micro ...
- oc70--NSArray1
// // main.m // NSArray是不可变的,一旦初始化完毕,就不能添加和删除了.类似于NSString和NSMutilString. #import <Foundation/Fou ...
- leetcode快排相关
leetcode:75颜色分类(3way).215数组中的第K个最大元素(normal) 3way private static void quick3waySort(int[] arr, int l ...
- NET运用String的十八层境界
古往今来,文本处理一直是所有编程语言的最基础的功能,也是最核心最重要的功能.任何初学者,如果想学一门编程语言,都要面对大量的文本处理.而或许有一天,即使你成了大师级的人物,也不敢说自己驾驭文本处理的能 ...