Another Meaning

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

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

题意:给你一个主串一个子串,然后主串中匹配到子串就可以把匹配部分改为*(也可以不改),问主串有多少钟不同的样子;

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf
const int mod=1000000007;
const int N=1e5+10; int la,lb;
ll dp[N];
char a[N],b[N];
ull ha[N],hb;
ull seed=13331; void init(){
hb=0;
for(int i=0;i<lb;i++)
hb=hb*seed+b[i];
ull base=1;
for(int i=1;i<=lb-1;i++) base*=seed;
ha[0]=a[0];
for(int i=1;i<=lb-1;i++)
ha[i]=ha[i-1]*seed+a[i];
for(int i=lb;i<la;i++)
ha[i]=(ha[i-1]-a[i-1-(lb-1)]*base)*seed+a[i];
} int main()
{
int cas,kk=0;
scanf("%d",&cas);
while(cas--){
scanf("%s",a);
scanf("%s",b);
la=strlen(a);lb=strlen(b);
if(la<lb) {printf("Case #%d: 1\n",++kk);CT;}
init();
for(int i=0;i<=lb-1;i++) dp[i]=1;
if(ha[lb-1]==hb) dp[lb-1]=2;
for(int i=lb;i<la;i++){
dp[i]=dp[i-1]%mod;
if(ha[i]==hb) dp[i]=(dp[i]+dp[i-lb])%mod;
}
printf("Case #%d: %lld\n",++kk,dp[la-1]%mod);
}
return 0;
}

  分析:错误点:

1.BKDRhash不太熟练,只会原来的最后输出&的形式,导致最后计算复杂;

改进:BKDRhash的形式:pre*seed+a[i],seed为13331之类的大素数,pre为i以前的哈希值;

a[i]就是字符

2,没有想到dp,当前下标i的话,dp[i]的数值,如果当前i并未匹配到子串,dp[i]=dp[i-1];

如果匹配到子串,dp[i]=dp[i-1]+dp[i-lb];

最新文章

  1. PAT 5-8 File Transfer (25分)
  2. LiveSDK初始化/登录时失败的解决办法
  3. RTX二次开发(二)(基于ASP.NET)
  4. Android笔记——Android中数据的存储方式(三)
  5. 在虚拟机环境下,电脑间拷贝配置好的伪分布式Hadoop环境,出现namenode不能启动的问题!
  6. CentOS 安装 Sun JDK
  7. 如何查看跟踪查看LINUX内核中的源码
  8. ubuntu下怎么合并windows下分割的zip包
  9. MFC中树控件CTreeCtrl的用法
  10. 【转】 UINavigationItem UINavigationBar 关系分析
  11. iOS所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程
  12. xml转义符
  13. XMPP协议的基本理解
  14. SVN的工作原理及流程手册
  15. 初入爬虫(java)
  16. python函数(一)调用函数
  17. Domination(概率DP)
  18. oracle 存储过程模板
  19. mongodb常用操作命令(待续)
  20. Checkpoint--实现步骤

热门文章

  1. python 文件写入
  2. ASP.NET练习③——AspNetChosmePager
  3. 修改源码去除zblog博客分类目录的RSS图标
  4. js 动态添加Table tr,选中与不选中checkbox行数NO的变化
  5. JS基础_while的练习1
  6. SIP笔记
  7. python3爬虫图片验证码识别
  8. java字符串大小写转换
  9. JS的 delete操作符 删除对象属性
  10. centos7andcentos6初始化脚本