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). ...
随机推荐
- Atitit main函数的ast分析 数组参数调用的ast astview解析
Atitit main函数的ast分析 数组参数调用的ast astview解析 1.1. Xxcls.main(new String[]{"","bb"}) ...
- python学习 数据类型之序列
一.序列(本文使用python3.5)############################################################# 列表.元组 字符窜都是序列#特点:#1 ...
- react3 组件
<body><!-- React 真实 DOM 将会插入到这里 --><div id="example"></div> <!- ...
- tabs左右滚动
$(function () { //IdivLeft小于0,说明左边还有菜单,菜单总数大于8 //IdivLeft等于0,说明菜单总数小于8 //IdivLeft大于0,说明右边还有菜单,菜单总数大于 ...
- 关于OpenVPN的入门使用
关于OpenVPN的入门使用 1.1源代码编译安装的初步了解 1.2 安装OpenVPN 1.3 生成证书.服务器端证书.客户端证书 1.4 关于server.ovpm & client.ov ...
- Entity Framework 5中应用表值函数进行Linq查询
Entity Framework 5引入了表值函数(Table-Valued Functions TVFs).表值函数的返回类型是一个Table类型,可用在SQL查询语句中.最简单的表值函数,读取客户 ...
- 使用Source Safe for SQL Server解决数据库版本管理问题
简介 在软件开发过程中,版本控制是一个广为人知的概念.因为一个项目可能会需要不同角色人员的参与,通过使用版本控制软件,可以使得项目中不同角色的人并行参与到项目当中.源代码控制使得代码可以存在多 ...
- java中Object.equals()简单用法
/* equals()方法默认的比较两个对象的引用! */ class Child { int num; public Child(int x){ num = x; } //人文的抛出运行时异常的好处 ...
- Angular从0到1:function(下)
1.前言 2.function(下) 2.13.angular.isArray(★★) angular.isArray用于判断对象是不是数组,等价于Array.isArray console.log( ...
- Windows 下搭建 Ruby 开发环境
1.从http://rubyinstaller.org/downloads/下载“rubyinstaller-2.1.5-x64.exe”. 2. 双击下载的程序进行安装,勾选如下图的选项.默认安装目 ...