博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6153 A Secret(扩展kmp)
阅读量:5137 次
发布时间:2019-06-13

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

A Secret

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)

Total Submission(s): 1530    Accepted Submission(s): 570

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.
 
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:            
 
 
题目大意:
给你两个字符串A,B,现在要你求B串的后缀在A串中出现的次数和后缀长度的乘积和为多少。
题解:
扩展KMP模板题,将s和t串都逆序以后就变成了求前缀的问题了,扩展KMP求处从i位置开始的最长公共前缀存于数组,最后通过将数组的值不为0的进行一个等差数列和的和就可以了。
#include
using namespace std;const int mod=1e9+7;const int N = 1000005;int Next[N];long long ex[N]; //即extand[]char p[N],t[N];int T;long long ans;void pre() // next[i]: 以第i位置开始的子串 与 T的公共前缀{ int lp=strlen(p); Next[0]=lp; int j=0,k=1; while(j+1

 

转载于:https://www.cnblogs.com/stepping/p/7404444.html

你可能感兴趣的文章
java 反射
查看>>
JS 作用域 实例分析
查看>>
ubuntu搭建ftp服务
查看>>
在eclipse中import java web项目时遇到的一些问题并将该项目通过tomcat发布
查看>>
ASP.NET页面运行机制
查看>>
MyBatis原理简介
查看>>
react中的children使用方法
查看>>
自己动手验证java和C++在动态性上的区别 求大侠斧正
查看>>
2018-2019-1 20189221《Linux内核原理与分析》第二周作业
查看>>
llinux基本指令
查看>>
ARP协议
查看>>
纯CSS画的基本图形(矩形、圆形、三角形、多边形、爱心、八卦等)
查看>>
解决Idea创建maven-archetype-webapp项目无java目录的问题
查看>>
ABP 用swagger UI测试API报401无权限访问问题
查看>>
Linux中fork()函数详解(转载)
查看>>
检测出来的结果怎么会是这样。。
查看>>
【python】如何安装BeautifulSoup4
查看>>
罗杰斯:做你喜欢的工作,你会变成个有钱人
查看>>
PyQt5中中文问题的不完全解决
查看>>
20155228 2016-2017-2 《Java程序设计》第9周学习总结
查看>>