Another Meaning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 526    Accepted Submission(s): 245

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是乘法的形式。..其实仔细想的话  他是加法的形式....weak
 
dp[i]表示到第i个字幕的时候能得到的 种类数
 
那么dp[i]=dp[i-1]---- 不替换的时候 
dp[i]+=dp[i-m]-------替换的时候 m是有不同含义的字符串的长度。
比如
hehehehe
hehe
可以替换的点是1、3、5
注意5这个点.替换的时候 dp[5]+=dp[1]  相当于 X*   dp[1]是X的种类数  *是我现在选择替换的情况。所以在原基础上要加上dp[1]。。。
没有理由用乘法 
/* ***********************************************
Author :guanjun
Created Time :2016/7/28 14:29:00
File Name :p401.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; int f[maxn];
int vis[maxn];
ll dp[maxn]; void getfail(char *p,int *f){
int m=strlen(p);
f[]=;f[]=;
for(int i=;i<m;i++){
int j=f[i];
while(j&&p[i]!=p[j])j=f[j];
f[i+]=p[i]==p[j]?j+:;
}
}
ll find(char* t,char* p,int* f){
int n=strlen(t),m=strlen(p);
getfail(p,f);
int j=;
cle(vis);
for(int i=;i<n;i++){
dp[i]=;
while(j&&p[j]!=t[i])j=f[j];
if(p[j]==t[i])j++;
if(j==m){
vis[i+]=;//标记末尾匹配起点
}
} dp[]=;
for(int i=;i<=n;i++){
dp[i]=dp[i-];
if(vis[i]){
dp[i]=(dp[i-m]+dp[i])%mod;
}
}
return dp[n];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
char p[maxn];
char t[maxn];
int T;
cin>>T;
for(int i=;i<=T;i++){
scanf("%s %s",t,p);
printf("Case #%d: %I64d\n",i,find(t,p,f));
}
return ;
}

HDU 5763Another Meaning的更多相关文章

  1. HDU 5763 Another Meaning

    HDU 5763 Another Meaning 题意:一个字串有可能在模式串出现多次,问有多少种可能出现的情况.关键是有重合的字串是不能同时计入的. 思路:先用kmp求出所有字串的位置.然后,dp. ...

  2. HDU 5763 Another Meaning KMP+DP

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Another Meaning Time Limit: 2000/1000 MS (Java/ ...

  3. HDU 5763 Another Meaning (kmp + dp)

    Another Meaning 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Description As is known to all, ...

  4. HDU 5763:Another Meaning(字符串匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=5763 Another Meaning Problem Description   As is known to ...

  5. 【动态规划】【KMP】HDU 5763 Another Meaning

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...

  6. HDU 5763 Another Meaning(FFT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解 ...

  7. HDU 5763 Another Meaning(DP+KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意: 给出一个字符串和一个模式串,模式串有两种意思,问这句话有几种意思. 思路:因为肯定要去字符串去找模 ...

  8. HDU 5763 Another Meaning dp+字符串hash || DP+KMP

    题意:给定一个句子str,和一个单词sub,这个单词sub可以翻译成两种不同的意思,问这个句子一共能翻译成多少种不能的意思 例如:str:hehehe   sub:hehe 那么,有**he.he** ...

  9. TTTTTTTTTTTTTT hdu 5763 Another Meaning 哈希+dp

    Another Meaning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

随机推荐

  1. viewDidLoad等相关函数调用

    viewDidLoad 此方法只有当view从nib文件初始化的时候才被调用.viewDidLoad用于初始化,加载时用到的. loadView 此方法在控制器的view为nil的时候被调用.虽然经常 ...

  2. luogu4388 付公主的矩形

    题面: 为了排解心中的怒气,她造了大量的稻草人来发泄.每天付公主都会把一些稻草人摆成一个R∗C的矩形,矩形的每个方格上都有一个稻草人.然后她站在这个矩形的左上角,向矩形的右下角射箭.付公主的箭术过人, ...

  3. Mac使用Aria2下载百度网盘,突破下载限速的方法教程

    百度网盘目前可以说是在国内网盘环境中一枝独秀,日常使用触及在所难免,尤其是对于喜欢下载资源的朋友来说,但是一些限制让它的使用越来越难,尤其是下载速度,普通用户的下载往往远低于自己的预期,特别是对于 M ...

  4. *****Python之进程线程*****

    Python之进程线程 Python的threading模块   并发编程: 操作系统:位于底层硬件与应用软件之间的一层. 工作方式:向下管理硬件,向上提供接口. 进程:资源管理单位(容器) 线程:最 ...

  5. linux虚拟环境搭建

    一.virtualenv的安装与使用 1.安装virtualenv pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualen ...

  6. POJ 2718 Smallest Difference(贪心 or next_permutation暴力枚举)

    Smallest Difference Description Given a number of distinct decimal digits, you can form one integer ...

  7. CodeForcesGym 100517B Bubble Sort

    Bubble Sort Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...

  8. JavaEE JDBC ResultSet内外移动

    ResultSet内外移动 @author ixenos 内外移动指位置光标的移动 内移动就是一个ResultSet得到后的那个光标! 外移动就是多个ResultSet的迭代 内移动 一般的数据库都不 ...

  9. ORACLE ASH/AWR

    (一) ASH 用户在ORACLE数据库中执行操作时,必然要创建相应的连接和会话,其中,所有当前的会话信息都保存在动态性能视图V$SESSION中,通过该视图,DBA可以查看用户实际执行的操作,或者当 ...

  10. SQLAlchemy(2):多表操作 & 连接方式及原生SQL

    一对多:ForeignKey multitb_models.py import datetime from sqlalchemy import create_engine # 引入 创建引擎 from ...