多校4 Another Meaning 5763
来源:互联网 发布:甜甜圈烤机软件 编辑:程序博客网 时间:2024/05/22 06:40
Another Meaning
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1266 Accepted Submission(s): 595
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.
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|
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
4hehehehehewoquxizaolehehewoquxizaoleheheheheheheowoadiuhzgneninouguriehiehieh
Sample Output
Case #1: 3Case #2: 2Case #3: 5Case #4: 1HintIn 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”.
题意:给一a串给一b串,问有几种匹配方式?(可匹配可不匹配)
思路:第一个字符匹配上了那后面Nb-1个字符都必须匹配,第一个字符没匹配上,后面的字符可匹配可不匹配,所以前后是有关系的,用DP,分两种情况匹配上没匹配上,两种情况又分别分为后面匹配上和后面没匹配上,列递推式,普通匹配极限数据会超时(虽然当时没超...)所以匹配加个kmp或哈希
代码:
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <cmath>#include <map>#define mod 1000000007using namespace std;const unsigned long long B = 1e8+7; /*mod*/const int MAXN = 100000+100;char a[MAXN],b[MAXN],tmp[MAXN];long long dp[MAXN];bool vis[MAXN];void hashfind(){ int al=strlen(a),bl=strlen(b); if(al>bl) { strcpy(tmp,a); strcpy(a,b); strcpy(b,tmp); } unsigned long long t=1,ah=0,bh=0; for(int i=0; i<al; i++) { t*=B; ah=ah*B+a[i]; bh=bh*B+b[i]; } for(int i=0; i+al<=bl; i++) { if(ah==bh)vis[i]=1; //匹配到的坐标 if(i+al<bl)bh=bh*B+b[i+al]-b[i]*t; }// return ans;}int main(){ int t; cin>>t; int cas = t; while(t--) { scanf("%s%s",b,a); memset(vis,0,sizeof vis); hashfind(); int m = strlen(b),n = strlen(a); for(int i = 0; i <= m; i++) dp[i] = 1; for(int i = m-n; i >=0; i--) { if(vis[i]) dp[i] = (dp[i+n] + dp[i+1])%mod; else dp[i] = dp[i+1]%mod; } cout<<"Case #"<<cas-t<<": "<<dp[0]<<endl; } return 0;}
0 0
- 多校4 Another Meaning 5763
- HDU 5763 Another Meaning(多校4)
- HDU 5763 Another Meaning
- HDU 5763 Another Meaning
- HDU 5763 Another Meaning
- HDOJ 5763 Another Meaning
- 【HDU】5763 Another Meaning
- hdu 5763 Another Meaning
- HDOJ 5763 Another Meaning
- hdu5763 多校4 Another Meaning【kmp+dp】
- DP-HDU-5763-Another Meaning
- HDU 5763 Another Meaning (DP)
- 【47.92%】【hdu 5763】Another Meaning
- hdu 5763 Another Meaning KMP+DP(多校)
- 2016 多校 Multi-University Training Contest 4 Another Meaning
- Another Meaning
- Another Meaning
- HDU 5763 Another Meaning (DP)
- window、location、location.href、self、top简单介绍
- Fragment懒加载
- 2016.8.6 学习总结
- 越亲密,越伤害读书_笔记
- 盒切在医学影像处理中的应用
- 多校4 Another Meaning 5763
- 高并发数据结构Disruptor解析(6)
- Google Gson的使用方法
- 队列,单调栈
- POJ-2002-Squares
- 杭电4349Xiao Ming's Hope
- Android:图解四种启动模式 及 实际应用场景讲解
- jQuery验证控件jquery.validate.js使用说明+中文API
- C++ enum的使用学习,一些基础内容的理解