HDU 5763:Another Meaning(字符串匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=5763
Another Meaning
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.
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
|A| <= 100000
|B| <= |A|
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 <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define N 100005
#define MOD 1000000007
/*
对于这个问题,显然可以进行DP:
令dp[i]表示到i结尾的字符串可以表示的不同含义数,那么考虑两种转移: 末尾不替换含义:dp[i - 1] 末尾替换含义:dp[i - |B|] (A.substr(i - |B| + 1,|B|) = B) 那么对于末尾替换含义的转移,需要快速判断BB能不能和当前位置的后缀匹配,kmp或者hash判断即可。 复杂度:O(N)
*/
long long dp[N];
string s, str; int main()
{
int t;
cin >> t;
for(int cas = ; cas <= t; cas++) {
memset(dp, , sizeof(dp));
cin >> s >> str;
int n = s.size();
int m = str.size();
for(int i = ; i < m; i++)
dp[i] = ;
for(int i = m; i <= n; i++) {
dp[i] = dp[i-];
string ss = s.substr(i - m, m);
if(ss == str)
dp[i] += dp[i-m] % MOD;
dp[i] %= MOD;
}
printf("Case #%d: ", cas);
cout << dp[n] << endl;
}
return ;
}
HDU 5763:Another Meaning(字符串匹配)的更多相关文章
- HDU 5763 Another Meaning
HDU 5763 Another Meaning 题意:一个字串有可能在模式串出现多次,问有多少种可能出现的情况.关键是有重合的字串是不能同时计入的. 思路:先用kmp求出所有字串的位置.然后,dp. ...
- HDU 1711 Number Sequence (字符串匹配,KMP算法)
HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...
- HDU 5763 Another Meaning KMP+DP
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Another Meaning Time Limit: 2000/1000 MS (Java/ ...
- HDU 5763 Another Meaning (kmp + dp)
Another Meaning 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Description As is known to all, ...
- HDU 5763 Another Meaning(DP+KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意: 给出一个字符串和一个模式串,模式串有两种意思,问这句话有几种意思. 思路:因为肯定要去字符串去找模 ...
- 【动态规划】【KMP】HDU 5763 Another Meaning
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...
- HDU 5763 Another Meaning(FFT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解 ...
- HDU 5763 Another Meaning dp+字符串hash || DP+KMP
题意:给定一个句子str,和一个单词sub,这个单词sub可以翻译成两种不同的意思,问这个句子一共能翻译成多少种不能的意思 例如:str:hehehe sub:hehe 那么,有**he.he** ...
- TTTTTTTTTTTTTT hdu 5763 Another Meaning 哈希+dp
Another Meaning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 1711 Number Sequence(字符串匹配)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- C# WPF 中用代码模拟鼠标和键盘的操作
原文:C# WPF 中用代码模拟鼠标和键盘的操作 原文地址 C#开发者都知道,在Winform开发中,SendKeys类提供的方法是很实用的.但是可惜的是,在WPF中不能使用这个方法了. 我们知道,在 ...
- WPF编游戏系列 之七 动画效果(2)
原文:WPF编游戏系列 之七 动画效果(2) 上一篇已经对关闭窗口图标进行了动画效果处理,本篇将对窗口界面的显示和关闭效果进行处理.由于所有的动画效果都是针对窗口界面的Canvas,所以 ...
- ASP.NET Core 2 学习笔记(一)开始
原文:ASP.NET Core 2 学习笔记(一)开始 来势汹汹的.NET Core似乎要取代.NET Framework,ASP.NET也随之发布.NET Core版本.虽然名称沿用ASP.NET, ...
- 一步一步造个IoC轮子(三):构造基本的IoC容器
一步一步造个Ioc轮子目录 一步一步造个IoC轮子(一):Ioc是什么 一步一步造个IoC轮子(二):详解泛型工厂 一步一步造个IoC轮子(三):构造基本的IoC容器 定义容器 首先,我们来画个大饼, ...
- Gralde 网络代理
Gralde 网络代理 Gradle在编译项目的时候,需要下载一些依赖.墙外的网络就需要设置代理了. 设置的方法,见文档: Accessing the web through a HTTP proxy ...
- PMC另类阐述
生产部门,坦克,铠甲战士,血厚硬气 业务部门,刺客,杀气十足,强势收割人头 采购部门,法师,在坦克身后持续输出 PMC,辅助,血不够厚扛不了伤害,输出不够拿不到人头,是团队中最容易被忽视的角色 坦克和 ...
- TLD单目标跟踪算法程序详解--OpenTLD Code 详解
TLD算法原理介绍:http://www.cnblogs.com/liuyihai/p/8306419.html OpenTLD源代码页: https://github.com/zk00006/Ope ...
- Advanced Installer 11.9基于IIS打包札记(For MySQL)
原文:Advanced Installer 11.9基于IIS打包札记(For MySQL) Mysql免安装前期部署 下载绿色命令行版本的mysql,将其放入到发布的程序发布包内,执行Update批 ...
- UWP StorageFile StorageFolder StorageFileHelper
//获取表示指定文件系统路径中的文件夹的 StorageFolder. StorageFolder folder1 = await StorageFolder.GetFolderFromPathAsy ...
- 用TTcpClient和TTcpServer进行文件的传输
发送数据时有Sendln,SendBuf,SendStream.接收数据时有Receiveln,ReceiveBuf,当时我很奇怪为什么没有ReceiveStream.因为很自然的想到是对应关系的.但 ...