A Secret

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 1666    Accepted Submission(s): 614

Problem Description
Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a present,which have a big secret.SF is interested in this secret and ask VS how to get it.There are the things that VS tell:
  Suffix(S2,i) = S2[i...len].Ni is the times that Suffix(S2,i) occurs in S1 and Li is the length of Suffix(S2,i).Then the secret is the sum of the product of Ni and Li.
  Now SF wants you to help him find the secret.The answer may be very large, so the answer should mod 1000000007.
 
Input
Input contains multiple cases.
  The first line contains an integer T,the number of cases.Then following T cases.
  Each test case contains two lines.The first line contains a string S1.The second line contains a string S2.
  1<=T<=10.1<=|S1|,|S2|<=1e6.S1 and S2 only consist of lowercase ,uppercase letter.
 
Output
For each test case,output a single line containing a integer,the answer of test case.
  The answer may be very large, so the answer should mod 1e9+7.
 
Sample Input
2
aaaaa
aa
abababab
aba
 
Sample Output
13
19

Hint

case 2:
Suffix(S2,1) = "aba",
Suffix(S2,2) = "ba",
Suffix(S2,3) = "a".
N1 = 3,
N2 = 3,
N3 = 4.
L1 = 3,
L2 = 2,
L3 = 1.
ans = (3*3+3*2+4*1)%1000000007.

 
扩展kmp 模板题
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define mod 1000000007
typedef long long ll;
int T;
char s[],t[];
int extend[],nex[];
void pre_ex_kmp(char x[],int m,int nex[])
{
nex[]=m;
int j=;
while(j+<m&&x[j]==x[j+])
j++;
nex[]=j;
int k=;
for(int i=; i<m; i++)
{
int p=nex[k]+k-;
int L=nex[i-k];
if(i+L<p+)
nex[i]=L;
else
{
j=max(,p-i+);
while(i+j<m&&x[i+j]==x[j])
j++;
nex[i]=j;
k=i;
}
}
}
void ex_kmp(char x[],int m,char y[],int n,int nex[],int extend[])
{
pre_ex_kmp(x,m,nex);
int j=;
while(j<n&&j<m&&x[j]==y[j])
j++;
extend[]=j;
int k=;
for(int i=; i<n; i++)
{
int p=extend[k]+k-;
int L=nex[i-k];
if(i+L<p+)
extend[i]=L;
else
{
j=max(,p-i+);
while(i+j<n&&j<m&&y[i+j]==x[j])
j++;
extend[i]=j;
k=i;
}
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
memset(extend,,sizeof(extend));
memset(nex,,sizeof(nex));
scanf("%s",s);
scanf("%s",t);
int len1=strlen(s);
int len2=strlen(t);
reverse(s,s+len1);
reverse(t,t+len2);
ex_kmp(t,len2,s,len1,nex,extend);
ll ans=;
ll n;
for(int i=; i<len1; i++)
{
if(extend[i])
{
n=extend[i]%mod;
ans=ans+(n*(n+)/)%mod;
ans%=mod; }
}
cout<<ans<<endl;
}
return ;
}

HDU 6153 扩展kmp的更多相关文章

  1. hdu 4333 扩展kmp+kmp重复字串去重

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...

  2. HDU 3336 扩展kmp

    题目大意: 找到字符串中所有和前缀字符串相同的子串的个数 对于这种前缀的问题,通常通过扩展kmp来解决 其实吧这是我第一次做扩展kmp的题目,原来确实看过这个概念,今天突然做到,所以这个扩展kmp的模 ...

  3. hdu 4333(扩展kmp)

    题意:就是给你一个数字,然后把最后一个数字放到最前面去,经过几次变换后又回到原数字,问在这些数字中,比原数字小的,相等的,大的分别有多少个.比如341-->134-->413-->3 ...

  4. HDU 6153 拓展KMP (2017CCPC)

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total ...

  5. HDU 3613 扩展KMP

    暴力枚举大水题,判断回文,扩展KMP #include <cstdio> #include <cstring> #include <algorithm> using ...

  6. HDU 2594 扩展kmp模板题

    题目大意: 给定两个字符串,在第一个字符串中找到一个最大前缀作为第二个字符串的后缀 #include <iostream> #include <cstdio> #include ...

  7. hdu 3613 扩展kmp+回文串

    题目大意:给个字符串S,要把S分成两段T1,T2,每个字母都有一个对应的价值,如果T1,T2是回文串(从左往右或者从右往左读,都一样),那么他们就会有一个价值,这个价值是这个串的所有字母价值之和,如果 ...

  8. HDU 6153 A Secret(扩展KMP模板题)

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total ...

  9. hdu 6153 思维+扩展kmp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 扩展kmp不理解的看下:http://www.cnblogs.com/z1141000271/p ...

随机推荐

  1. 【php增删改查实例】第八节 - 部门管理模块(编写PHP程序)

    首先,在同级目录新建一个query.php文件: 接着,去刷新页面,打开F12,NetWork,看看当前的请求能不能走到对应的php文件? 这就说明datagrid确实能够访问到query.php 只 ...

  2. springboot项目生成jar包(带静态资源)方法

    [Maven]在pom.xml文件中使用resources插件的小作用 不过war包比较实用,毕竟独立的tomcat比较好控制

  3. 重磅发布丨乐维监控:全面兼容云平台,助力企业DevOps转型升级!

    2019年伊始,我们迎来了乐维监控的又一重大功能更新——云平台监控,这将有效帮助企业将云上.云下数据聚合,方便统一化的监控管理与维护!未来,乐维监控每一次的产品功能及版本更新,我们都将第一时间于此发布 ...

  4. 关于T/G/M/K

    //扫盲贴 K, G, T,都是表数量,只是个数字,在不同的场合下表示的不同.在计算机行业中,这几个量可用来表示数据传输速度和容量,下面分别讨论,希望不了解的朋友不要被某知道上的误解了.如果有什么错误 ...

  5. PAT甲题题解-1058. A+B in Hogwarts (20)-大水题

    无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...

  6. PAT甲级题解-1100. Mars Numbers (20)-字符串处理

    没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...

  7. process.tar.gz

    exec1.c #include <stdio.h> #include <unistd.h> int main() { char *arglist[3]; arglist[0] ...

  8. [转载]ValidationExpression验证规则

    ValidationExpression验证规则  在ASP.NET中,ValidationExpression 验证规则属性可以根据自已的需要,对输入的数据进行限制,其常用符号如下表所示: 符号  ...

  9. Spring sprint @ ninth day

    时间 日期 地点 工作 20:05 5.20 九实 集成网络助手项目 遇到的困难:集成遇到,画了好久的rc文件,编译不了.rc文件也不能复制,还得重画.郁闷!!!

  10. 第二个Sprint冲刺第四天(燃尽图)