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

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

A Secret

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

Total Submission(s): 817    Accepted Submission(s): 321

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
题目容易理解,匹配个数
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>y?x:y) #define min(x,y) (x
-1) { if(sb[j]==sb[i]) {nex[i+1]=j+1,val[i+1]+=val[j+1],val[i+1]%=MOD;break;} j=nex[j]; } } /*for(i=1;i<=lb;i++) { printf("%lld ",val[i]); } printf("\n");*/}ll matchfind(){ ll ans=0; k=0; for(i=0;i
=0;j=nex[j]) { if(sa[i]==sb[j]) { k=j+1; break; } } ans=(ans+val[k])%MOD; } return ans;}int main(){ scanf("%lld",&t); while(t--) { scanf("%s %s",sa,sb); la=strlen(sa),lb=strlen(sb); reverse(sa,sa+la),reverse(sb,sb+lb); getnext(); printf("%lld\n",matchfind()); } return 0;}/* a b a b b b a b a next 0 0 1 2 0 0 1 2 3val 1 2 4 6 5 6 8 10 13valfj 1 2 3+1 4+2 5 6 7+1 8+2 9+4=9+3+1::next[9]=next[3]=next[1];*/

 

转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7399163.html

你可能感兴趣的文章
[Ocean Modelling for Begineers] Ch3. Basics of Geophysical Fluid Dynamics
查看>>
SqlServer性能优化:创建性能监视器(二)
查看>>
Sqlserver在现有数据库中插入数据
查看>>
使用jquery对数组进行分页,或者是对ul li中的数据进行隐藏显示
查看>>
win7(x64)matlab2010a 编译器安装
查看>>
一头扎进 Java IO中-------java IO文件
查看>>
20181018 考试记录
查看>>
题解 P2613 【【模板】有理数取余】
查看>>
ios-UIWebView中js和oc代码的互调
查看>>
类型转换
查看>>
“天下文章一大抄”的时代已经过去
查看>>
线性布局和相对布局
查看>>
appium中driver.wait报IllegalMonitorStateException的解释
查看>>
3 SQL 聚合与排序
查看>>
Getting Started with XlsxWriter
查看>>
c++有默认参数的函数---4
查看>>
扭曲你的数据,让其变得具有视觉吸引力
查看>>
selenium+Python(Js处理click失效)
查看>>
喵哈哈村的魔法考试 Round #1 (Div.2)
查看>>
[转]Docker中的镜像
查看>>