HDU 3336 Count the string 查找匹配字符串
Count the string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4105 Accepted Submission(s): 1904
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.
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.
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define MOD 10007
char s[];
int a[];
int main()
{
int i, j, n, t; cin>>t;
while(t--)
{
cin>>n;
scanf("%s", s);
int L = ;
for(i = ; s[i]; i++)
{
if(s[i] == s[]) a[L++] = i;//首先记录第一个字符出现的位置
}
int count = L, X = ;
cout<<count<<endl;
for(i = ; s[i]; i++)
{
X = ;
for(j = ; j < L; j++)//直接比较已经匹配的上一个位置,是否匹配下一个字符
{
if(s[a[j]+] == s[i])
{
count += ;
count %= MOD;
a[X++] = a[j] + ;
}
}
L = X;
}
printf("%d\n", count);
}
return ;
}
HDU 3336 Count the string 查找匹配字符串的更多相关文章
- 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) ...
- 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 ...
- HDU 3336 Count the string(next数组运用)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3336: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&dp
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- HDU 3336 Count the string KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...
- 【HDU 3336 Count the string】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU 3336——Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- HDU 3336 - Count the string(KMP+递推)
题意:给一个字符串,问该字符串的所有前缀与该字符串的匹配数目总和是多少. 此题要用KMP的next和DP来做. next[i]的含义是当第i个字符失配时,匹配指针应该回溯到的字符位置. 下标从0开始. ...
随机推荐
- 一致性hash在分布式系统中的应用
场景 如果要设计一套KV存储的系统,用户PUT一个key和value,存储到系统中,并且提供用户根据key来GET对应的value.要求随着用户规模变大,系统是可以水平扩展的,主要要解决以下几个问题. ...
- OpenCV学习(13) 细化算法(1)
程序编码参考经典的细化或者骨架算法文章: T. Y. Zhang and C. Y. Suen, "A fast parallel algorithm for thinning digita ...
- TensorFlowIO操作(三)------图像操作
图像操作 图像基本概念 在图像数字化表示当中,分为黑白和彩色两种.在数字化表示图片的时候,有三个因素.分别是图片的长.图片的宽.图片的颜色通道数.那么黑白图片的颜色通道数为1,它只需要一个数字就可以表 ...
- MySQL服务器安装完之后如何调节性能
原文作者: Peter Zaitsev原文来源: http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server ...
- Drupal、IoT 和开源硬件之间的交集
导读 来认识一下Amber Matz,她是来自 Lullabot Education 旗下的Drupalize.Me的产品经理以及培训师.当她没有倒腾 Arduino.Raspberry Pi 以及电 ...
- Jenkins 安装与使用--实例
參考了博客Jenkins master在windows上安装 Jenkins的主要功能是监视反复工作的运行,比如软件project的构建详细地: *软件的持续构建和測试 本质上提供了一个易于使用的持续 ...
- 主从复制时报:ERROR 1794 (HY000): Slave is not configured or failed to initialize properly. You must at least set --server-id to enable either a master or a slave. Additional error messages can be found in t
centos 6.5 mysql5.7 在从库作stop slave时报: error:ERROR 1794 (HY000): Slave is not configured or failed to ...
- Linux-正则表达式的POSIX规范及流派
Linux/Unix工具与正则表达式的POSIX规范 对正则表达式有基本了解的读者,一定不会陌生『\d』.『[a-z]+』之类的表达式,前者匹配一个数字字符,后者匹配一个以上的小写英文字母.但是如果你 ...
- Ruby 和 Python 分析器是如何工作的?
你好! 我作为一名编写Ruby profiler的先驱,我想对现有的Ruby和Python profiler如何工作进行一次调查. 这也有助于回答很多人的问题:“你怎么写一个profiler?” 在这 ...
- CI:关于计算智能
该书认为,当前的计算智能起源于人工智能和生物智能.人工智能的起源大约可以追溯到50年以前,而计算智能这个术语则仅仅出现于10年以前.计算智能由几个部分组成,即人工智能.模糊集和模糊逻辑.神经网络(有时 ...