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)的更多相关文章

  1. HDU 5763 Another Meaning (kmp + dp)

    Another Meaning 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Description As is known to all, ...

  2. HDU 5763 Another Meaning(FFT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5763 [题目大意] 给出两个串S和T,可以将S串中出现的T替换为*,问S串有几种表达方式. [题解 ...

  3. HDU - 4333 Revolving Digits(扩展KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4333 题意 一个数字,依次将第一位放到最后一位,问小于本身的数的个数及等于本身的个数和大于本身的个数,但是要注意 ...

  4. HDU 5510:Bazinga(暴力KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5510 Bazinga Problem Description   Ladies and gentlemen, p ...

  5. HDU 6153 A Secret(扩展kmp)

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total ...

  6. HDU 3613 Best Reward(扩展KMP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3613 [题目大意] 一个字符串的价值定义为,当它是一个回文串的时候,价值为每个字符的价值的和,如果 ...

  7. HDU 5763 Another Meaning

    HDU 5763 Another Meaning 题意:一个字串有可能在模式串出现多次,问有多少种可能出现的情况.关键是有重合的字串是不能同时计入的. 思路:先用kmp求出所有字串的位置.然后,dp. ...

  8. HDU 2222 Keywords Search(查询关键字)

    HDU 2222 Keywords Search(查询关键字) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K ...

  9. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. PHP 支持8种基本的数据类型。

    四种标量类型:boolean (布尔型):这是最简单的类型,只有两种取值,可以为 TRUE/true 或 FALSE/false ,不区分大小写.详细请查看:PHP布尔类型(boolean)integ ...

  2. paintschainer项目

    github:https://github.com/pfnet/PaintsChainer tensorflow实现:https://github.com/mizti/tensor_paint 在线测 ...

  3. Flowers---hdu4325(区间处理 离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:有n种花,每种花都有自己的开花时间段从S到E,有m个查询,每个查询都是一个时间点,求这一时 ...

  4. phpcms调用子栏目名称/文章怎么操作

    phpcms调用子栏目名称相对比较简单一些,也是用{pc:content}来调用,只是把action设置为category,catid如果为0的话是调用所有一级栏目,如果是其他数字的话,则调用相应栏目 ...

  5. libx264 安卓编译

    https://github.com/RoyGuanyu/build-scripts-of-ffmpeg-x264-for-android-ndk/blob/master/ffmpeg/build_a ...

  6. django之自定义软删除Model

    软删除 简单的说,就是当执行删除操作的时候,不正真执行删除操作,而是在逻辑上删除一条记录.这样做的好处是可以统计数据,可以进行恢复操作等等. 预备知识 Managers Managers 是djang ...

  7. POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage

    题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...

  8. 我的第一次NGS分析操作

    部分参考自:生物信息学100个基础问题 —— 番外2: 用Anaconda快速搭建生物信息学分析平台 - 孟浩巍的文章 - 知乎 https://zhuanlan.zhihu.com/p/357114 ...

  9. Mysql—(2)—

    数据库存储引擎 (更多详见) 一 什么是存储引擎 mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件应该有不同的类型:比如存文本用txt类型,存 ...

  10. AviMemDc: a C++ class

    AviMemDc: a C++ class        This class is used in the Avi Examples.The header fileAviMemDC.h /*    ...