HDU 5763 Another Meaning(DP+KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=5763
题意:
给出一个字符串和一个模式串,模式串有两种意思,问这句话有几种意思。
思路:
因为肯定要去字符串去找模式串,所以首先用KMP计算next数组,然后用动态规划,d[i]表示分析到第i个字符时有多少种意思。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std; const int maxn=1e5;
const int MOD=; char a[maxn],b[maxn];
int _next[maxn];
int d[maxn]; void get_next()
{
int i=-,j=;
_next[]=-;
while(j<strlen(b))
{
if(i==-||b[i]==b[j])
_next[++j]=++i;
else
i=_next[i];
}
} int KMP(int n,int m)
{
int i, j;
i = j = ;
while (i<n)
{
if (j == - || a[i] == b[j])
{
if(i>) d[i]=d[i-];
i++;
j++;
if (j == m) d[i-]=(d[i--(j--_next[j-])]+d[i--m]+)%MOD;
}
else
j = _next[j];
}
} int main()
{
//freopen("D:\\input.txt","r",stdin);
int T;
scanf("%d",&T);
for(int kase=;kase<=T;kase++)
{
scanf("%s",&a);
scanf("%s",&b);
int n=strlen(a); int m=strlen(b);
memset(d,,sizeof(d));
get_next();
KMP(n,m);
printf("Case #%d: ",kase);
printf("%d\n",d[n-]+);
}
return ;
}
HDU 5763 Another Meaning(DP+KMP)的更多相关文章
- 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(FFT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解 ...
- HDU - 4333 Revolving Digits(扩展KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意 一个数字,依次将第一位放到最后一位,问小于本身的数的个数及等于本身的个数和大于本身的个数,但是要注意 ...
- HDU 5510:Bazinga(暴力KMP)
http://acm.hdu.edu.cn/showproblem.php?pid=5510 Bazinga Problem Description Ladies and gentlemen, p ...
- HDU 6153 A Secret(扩展kmp)
A Secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 256000/256000 K (Java/Others)Total ...
- HDU 3613 Best Reward(扩展KMP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3613 [题目大意] 一个字符串的价值定义为,当它是一个回文串的时候,价值为每个字符的价值的和,如果 ...
- HDU 5763 Another Meaning
HDU 5763 Another Meaning 题意:一个字串有可能在模式串出现多次,问有多少种可能出现的情况.关键是有重合的字串是不能同时计入的. 思路:先用kmp求出所有字串的位置.然后,dp. ...
- HDU 2222 Keywords Search(查询关键字)
HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...
- HDU 5860 Death Sequence(死亡序列)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
随机推荐
- NoSQL文章
MongoDB Bugsnag的MongoDB分片集群使用经验
- (4.20)SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧
转自:指尖流淌 https://www.cnblogs.com/zhijianliutang/p/4085546.html SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧 ...
- Zabbix server(离线版)安装手册
由于zabbix server需要依赖MySQL及PHP的相关依赖,因此需要先安装好MySQL及PHP的相关依赖后方可安装zabbixserver. 安装MySQL 目录mysql下的rpm 1.新建 ...
- Oracle优化-SQL_TRACE
思维导图 Oracle优化10-SQL_TRACE解读 Oracle优化11-10046事件 概述 当我们想了解一条SQL或者是PL/SQL包的运行情况时,特别是当他们的性能非常差时,比如有的时候看起 ...
- 6 TensorFlow实现cnn识别手写数字
------------------------------------ 写在开头:此文参照莫烦python教程(墙裂推荐!!!) ---------------------------------- ...
- matlab手写神经网络实现识别手写数字
实验说明 一直想自己写一个神经网络来实现手写数字的识别,而不是套用别人的框架.恰巧前几天,有幸从同学那拿到5000张已经贴好标签的手写数字图片,于是我就尝试用matlab写一个网络. 实验数据:500 ...
- SMO算法精解
本文参考自:https://www.zhihu.com/question/40546280/answer/88539689 解决svm首先将原始问题转化到对偶问题,而对偶问题则是一个凸二次规划问题,理 ...
- Windows常见宏的使用
WIN32_LEAN_AND_MEAN 1. 参考资料:https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs. ...
- Apple Pay编程指导
1.About Apple PayApple Pay是一种移动支付技术,让使用者把它们对真实的物品和服务的支付信息以一种方便和安全的方式给你. 对于在app中给出的数字物品和服务,可查看In-App ...
- tensorflow(二)----线程队列与io操作
一.队列和线程 1.队列: 1).tf.FIFOQueue(capacity, dtypes, name='fifo_queue') 创建一个以先进先出的顺序对元素进行排队的队列 参数: capaci ...