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. python基础-第七篇-7.1初识类和对象

    创建类和对象 刚开始我们接触得多的编程方式为面向过程编程,这种方式就是根据业务逻辑从上往下垒代码,后来又出现了函数式编程,就是为了提高代码的重用性,减轻程序猿的工作量--而今天我们即将学的 面向对象编 ...

  2. Sqoop简介及使用

    一.Sqoop概述 1)官网 http://sqoop.apache.org/ 2)场景 传统型缺点,分布式存储.把传统型数据库数据迁移. Apache Sqoop(TM)是一种用于在Apache H ...

  3. 十個必用的 Vim Plugin

    ◎ The NERD Tree 操作 Vim 時,通常都在 Terminal 底下作用,無法像一般的 GUI    應用程式可以以樹狀目錄來瀏覽檔案. The NERD Tree    是一將檔案目錄 ...

  4. Linux下多线程的重要知识点

    线程属性: typedef struct { int                              detachstate;   线程的分离状态 int                   ...

  5. 0701-spring cloud config-简介、Config Server开发、Config Client开发

    一.概述 参看地址: https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_spring_ ...

  6. 关于手机适配中的rem的学习随笔

    githup 下载地址 :https://github.com/comjustforfun/remformobile adaptivejs利用rem解决移动端页面开发的自适应问题 页面模板初始化的时候 ...

  7. mysql lock

    http://blog.chinaunix.net/uid-21505614-id-289450.html http://bbs.csdn.net/topics/340127237 http://ww ...

  8. To keep up-to-date with Latest Jordans 2016

    The Latest Jordans 2016 will feature cement speckling because the base, Reflect Silver accents, a a ...

  9. WooCommerce Shortcode 简码使用方式说明

    WooCommerce 自帶的几个简易代码,可以用来插入文章和页面內容里面.下面简码安裝时会自动建立,因此,应该不需要使用在其他地方 : [woocommerce_cart] – 顯示購物車頁面 [w ...

  10. Java基础知识陷阱(五)

    本文发表于本人博客. 今天我来说说关于静态变量初始化.数组.==与equals的问题,看下面代码: public class Test{ private final int age; private ...