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. Luogu P4299 首都 LCT

    既然是中文题目,这里便不给题意. 分析: 这个题的做法据说是启发式合并? 但是我不会啊…… 进入正题,LCT是怎样做掉这道题的.记得在前面的一篇<大融合>的题解中,介绍过LCT维护子树信息 ...

  2. Python之面向对象多态

    Python之面向对象多态 多态与多态性: 多态: 多态是指一类事物有多种形态,一个抽象类有多个子类,因而多态的概念依赖于继承. 1.序列类型有多种形态:字符串.列表.元组. 2.动物有多种形态:Pe ...

  3. POJ3641 (快速幂) 判断a^p = a (mod p)是否成立

    Description Fermat's theorem states that for any prime number p and for any integer a > 1, ap = a ...

  4. c++中的三角函数

    c++中想求cos或sin: 1.首先得包含头文件,include<math.h> 2.sin(),cos(),中是弧度数,即若是角度a,则应写成cou<<sin(a*pi/1 ...

  5. python标准库笔记

    1.python互联网数据处理模块 base64数据编码 二进制数据 encode ASCII字符 ASCll字符 decode 二进制数据 json数据交换格式 轻量的数据交换格式,json暴露的A ...

  6. [luoguP1439] 排列LCS问题(DP + 树状数组)

    传送门 无重复元素的LCS问题 n2 做法不说了. nlogn 做法 —— 因为LCS问题求的是公共子序列,顺序不影响答案,影响答案的只是两个串的元素是否相同,所以可以交换元素位置. 首先简化一下问题 ...

  7. 【NOIP2017练习】跳跃切除子序列(模拟)

    题意: 思路: 已放弃 #include <bits/stdc++.h> typedef long long LL; int main(){ int T; scanf("%d&q ...

  8. Linux下汇编语言学习笔记51 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  9. [bzoj2229][Zjoi2011]最小割_网络流_最小割树

    最小割 bzoj-2229 Zjoi-2011 题目大意:题目链接. 注释:略. 想法: 在这里给出最小割树的定义. 最小割树啊,就是这样一棵树.一个图的最小割树满足这棵树上任意两点之间的最小值就是原 ...

  10. Just a Hook-HDU1698(线段树求区间)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...