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. JDBC详解系列(一)之流程

    ---[来自我的CSDN博客](http://blog.csdn.net/weixin_37139197/article/details/78838091)--- JDBC概述   使用JDBC也挺长 ...

  2. Java设计模式之适配器设计模式(项目升级案例)

    今天是我学习到Java设计模式中的第三个设计模式了,但是天气又开始变得狂热起来,对于我这个凉爽惯了的青藏人来说,又是非常闹心的一件事儿,好了不管怎么样,目标还是目标(争取把23种Java设计模式接触一 ...

  3. [摘抄]从 GitHub 身上学到的 3 个创业经验

    1.找一个大问题去解决 让 Git 更容易使用是 GitHub 的目标,但它从来不是 GitHub 的最终目标.GitHub 的真正目标是让协作和编写软件变得更容易.世界上每一个软件开发者都在努力解决 ...

  4. JVM源码---教你傻瓜式编译openjdk7(JAVA虚拟机爱好者必看)

    LZ经过一个星期断断续续的研究,终于成功的搞定了JDK的成功编译与调试.尽管网络上的教程也有不少,包括源码中也有自带的编译步骤说明,但真正自己动手的话,还是会遇到不少意料之外的错误. 为了方便各位猿友 ...

  5. Ubuntu16.4下QT配置opencv3.1+FFmpeg

    安装依赖环境 sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config ...

  6. Nextcloud13私有云盘安装指南

    一.环境说明: ※操作系统版本CentOS 7.5 Minimal-1804 ※操作系统版本已经使用163 YUM源 ※ Nextcloud版本 13.05 ※ 数据库使用MariaDB,安装在同一台 ...

  7. wordpress学习五: 通过wordpress_xmlrpc的python包远程操作wordpress

    wordpress提供了丰富的xmlrpc接口api来供我们远程操控wp的内容.伟大的开源社区有人就将这些api做了一下封装,提供了一个功能比较完整的python库,库的使用文档地址http://py ...

  8. Alpha版总结会议——班级派

    一.开会的过程 在周一下午上课的最后20分钟内,我们组进行了“班级派”的alpha版的总结会议.首先进行的是分析目前的版本情况,每个人说了自己的进度,包括已经完成的以及即将要完成的.随后是分析前段时间 ...

  9. 框架-Spring

    项目中都用到了Spring.Mybatis.SpringMVC框架,首先来谈一谈Spring框架,Spring框架以IOC.AOP作为主要思想. IOC----控制反转 IOC的全称为Inversio ...

  10. Inside the Social Network’s (Datacenter) Network

    摘要: 大量服务提供商投资越来越多的更大数据中心来保证基础计算需求以支持他们的服务.因此,研究人员和行业从业者都集中了大量的努力设计网络结构有效互连和管理流量以保证这些数据中心的性能.不幸的是,数据中 ...