Problem Description
As is known to all, in many cases, a word has two meanings. Such as “hehe”, which not only means “hehe”, but also means “excuse me”. 
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.
 
Input
The first line of the input gives the number of test cases T; T test cases follow.
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|

 
Output
For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the number of the different meaning of this sentence may be. Since this number may be quite large, you should output the answer modulo 1000000007.
 
Sample Input
4
hehehe
hehe
woquxizaolehehe
woquxizaole
hehehehe
hehe
owoadiuhzgneninougur
iehiehieh
 
Sample Output
Case #1: 3
Case #2: 2
Case #3: 5
Case #4: 1

Hint

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”.

 
思路:递推(DP) 当前位置以前的语句的含义种数为包含当前多语义与不包含;
 
代码如下:
#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的更多相关文章

  1. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  2. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  3. 2016暑假多校联合---Substring(后缀数组)

    2016暑假多校联合---Substring Problem Description ?? is practicing his program skill, and now he is given a ...

  4. 2016暑假多校联合---To My Girlfriend

    2016暑假多校联合---To My Girlfriend Problem Description Dear Guo I never forget the moment I met with you. ...

  5. 2016暑假多校联合---A Simple Chess

    2016暑假多校联合---A Simple Chess   Problem Description There is a n×m board, a chess want to go to the po ...

  6. 2016暑假多校联合---Death Sequence(递推、前向星)

    原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...

  7. 2016暑假多校联合---Counting Intersections

    原题链接 Problem Description Given some segments which are paralleled to the coordinate axis. You need t ...

  8. 2016暑假多校联合---Joint Stacks (STL)

    HDU  5818 Problem Description A stack is a data structure in which all insertions and deletions of e ...

  9. 2016暑假多校联合---GCD

    Problem Description Give you a sequence of N(N≤100,000) integers : a1,...,an(0<ai≤1000,000,000). ...

随机推荐

  1. EF架构~linq模拟left join的两种写法,性能差之千里!

    回到目录 对于SQL左外连接我想没什么可说的,left join将左表数据都获出来,右表数据如果在左表中不存在,结果为NULL,而对于LINQ来说,要实现left join的效果,也是可以的,在进行j ...

  2. 描述一下C#中索引器的实现过程,是否只能根据数字进行索引?

    不是.可以用任意类型. 索引器是一种特殊的类成员,它能够让对象以类似数组的方式来存取,使程序看起来更为直观,更容易编写. 1.索引器的定义 C#中的类成员可以是任意类型,包括数组和集合.当一个类包含了 ...

  3. Atitit.java expression fsm 表达式词法分析引擎 v2 qaa.docx

    Atitit.java expression fsm 表达式词法分析引擎 v2 qaa.docx C:\0workspace\AtiPlatf_cms\src\com\attilax\fsm\Java ...

  4. Atitit.软件与编程语言中的锁机制原理attilax总结

    Atitit.软件与编程语言中的锁机制原理attilax总结 1. 用途 (Db,业务数据加锁,并发操作加锁.1 2. 锁得类型 排它锁 "互斥锁 共享锁 乐观锁与悲观锁1 2.1. 自旋锁 ...

  5. java 线程安全 Lock

    java.util.concurrent.locks 对于线程安全我们前面使用了synchronized关键字,对于线程的协作我们使用Object.wait()和Object.notify().在JD ...

  6. JavaScript对浏览器的URL进行编码、解码

    关于url编码,js有三个函数.有三个解码方法,escape,encodeURI,encodeURIComponent().有三个解码方法,unescapse,decodeURI,decodeURIC ...

  7. java 中获取2个时间段中所包含的周数(股票的周数->从周六到周五)

    Calendar 类中是以周日为开始的第一天的,所以Calendar.DAY_OF_WEEK为1的时候是周日. 在股票中有日K 周K和月K的数据.  在此之中的周K是指交易日中一周的数据,周六到周五为 ...

  8. LVS负载平衡集群(没成型)

    LVS:可以实现高可用的.可伸缩的Web.Mail.Cache和Media等网络服务,实现一个可高用.高性能.低成本的服务器应用软件 LVS集群组成: 前端:负载均衡层 --由一台或多台负载调度器构成 ...

  9. 前端工程师技能之photoshop巧用系列扩展篇——自动切图

    × 目录 [1]初始设置 [2]自动切图 前面的话 随着photoshop版本的不断升级,软件本身增加了很多新的功能,也为切图工作增加了很多的便利.photoshop最新的版本新增了自动切图功能,本文 ...

  10. MyEclipse在搭建s2sh时 如何 uninstalled facet

    在资源管理器中:找到当前[项目的根目录],在[.setting]目录中, 找到[org.eclipse.wst.common.project.facet.core.xml]文件. 用[文本编辑器工具] ...