2016暑假多校联合---Another Meaning
Today, ?? is chating with MeiZi online, MeiZi sends a sentence A to ??. ?? is so smart that he knows the word B in the sentence has two meanings. He wants to know how many kinds of meanings MeiZi can express.
Each test case contains two strings A and B, A means the sentence MeiZi sends to ??, B means the word B which has two menaings. string only contains lowercase letters.
Limits
T <= 30
|A| <= 100000
|B| <= |A|
In the first case, “ hehehe” can have 3 meaings: “*he”, “he*”, “hehehe”.
In the third case, “hehehehe” can have 5 meaings: “*hehe”, “he*he”, “hehe*”, “**”, “hehehehe”.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const long long mod=1e9+; char s[];
char ss[];
int next1[];
long long num[];
int pos[]; void makenext1(const char P[])
{
int q,k;
int m = strlen(P);
next1[]=;
for (q = ,k = ; q < m; ++q)
{
while(k > && P[q] != P[k])
k = next1[k-];
if (P[q] == P[k])
{
k++;
}
next1[q] = k;
}
} long long calc(char T[],char P[])
{
int n,m;
int i,q;
int tot=;
n = strlen(T);
m = strlen(P);
makenext1(P);
for(i=,q = ; i < n; ++i)
{
while(q>&&P[q]!=T[i])
q=next1[q-];
if(P[q]==T[i])
{
q++;
}
if(q==m)
{
long long flag=;
pos[tot]=i-m+;
if(tot>)
{
if(pos[tot-]+m<=pos[tot])
{
num[tot]=(*num[tot-])%mod;
}
else
{
num[tot]=num[tot-]%mod;
for(int h=tot-;h>=;h--)
{
if(pos[h]+m<=pos[tot])
{
num[tot]=(num[tot]+num[h])%mod;
flag=; ///当之前不存在不相重叠的语句时;
break;
}
}
num[tot]=(num[tot]+flag)%mod;
}
}
else
{
num[tot]=;
}
tot++;
}
}
if(tot==) return ;
return num[tot-];
} int main()
{
int T;
int Case=;
cin>>T;
while(T--)
{
scanf("%s%s",s,ss);
printf("Case #%d: %lld\n",Case++,calc(s,ss));
// cout<<(calc(s,ss)%mod+mod)%mod<<endl;
}
return ;
}
2016暑假多校联合---Another Meaning的更多相关文章
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- 2016暑假多校联合---Substring(后缀数组)
2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...
- 2016暑假多校联合---To My Girlfriend
2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...
- 2016暑假多校联合---A Simple Chess
2016暑假多校联合---A Simple Chess Problem Description There is a n×m board, a chess want to go to the po ...
- 2016暑假多校联合---Death Sequence(递推、前向星)
原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...
- 2016暑假多校联合---Counting Intersections
原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...
- 2016暑假多校联合---Joint Stacks (STL)
HDU 5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...
- 2016暑假多校联合---GCD
Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...
随机推荐
- MVVM架构~knockoutjs系列之为Ajax传递Ko数组对象
返回目录 一些要说的 这是一个很有意思的题目,在KO里,有对象和数组对象两种,但这两种对象对外表现都是一个function,如果希望得到他的值,需要进行函数式调用,如ko_a(),它的结果为一个具体值 ...
- Atitit 图像处理底色变红的解决
Atitit 图像处理底色变红的解决 1.1. 原因 ImageIO bug ,alpha通道应该在保存jpg的时候排除1 1.2. 解决,自己移除alpha通道即可1 2. Image sav ...
- JSP连接mysql数据库的重点
1:用mysql驱动把mysql与tomcat的连接起来.把mysql驱动包(不用解压)放到Tomcat安装目录中lib文件夹下即可. 2:然后在自己的新建的web应用程序上面就可以下下面的代码 3: ...
- SQLServer查看死锁
SQLServer查看死锁 if exists ( select * from sys.procedures where name like '%USP_ShowLocks%' ) drop proc ...
- Mybatis中SqlMapper配置的扩展与应用(2)
三.子表删除兼容问题 这个问题,使用SQL配置函数不太好处理,而且就算使用SQL配置函数,也不够直观,有点自动生成SQL的意味,太Hibernate了(不过要是可以兼收Hibernate和Mybati ...
- 快速入门系列--MVC--03控制器和IOC应用
Asp.net MVC也接触好久了,但由于自己一直主要负责后台,尤其是数据库方面的工作对于该框架并没有一个很好的了解,尤其是蒋金楠大师的ASP.NET MVC4框架剖析一书都买了2年多了,真正认真看过 ...
- 分享几个asp.net开发中的小技巧
下面这几个,是在实际开发或阅读中发现的一些问题,有些甚至是有很多年开发人员写出的代码,也是很多人经常犯的错误.各位可以看看,你有没有躺着中枪. 第一个,对整型变量进行非null判断. // a 是in ...
- Docker之Linux UnionFS
UnionFS UnionFS是一种为Linux,FreeBSD和NetBSD操作系统设计的把其他文件系统联合到一个联合挂载点的文件系统服务.它使用branch把不同文件系统的文件和目录"透 ...
- JS实现弹出层对话框
点击按钮后,弹出层对话框,可交互,点击关闭后才关闭掉对话框. 效果图: 源码: <!doctype html> <html> <head> <meta cha ...
- PHP面向对象中的重要知识点(二)
1. __toString: 当对象被打印时,如果该类定义了该方法,则打印该方法的返回值,否则将按照PHP的缺省行为输出打印结果.该方法类似于Java中的toString(). <?php cl ...