题目链接:hdu_5763_Another Meaning

题意:

一个文本串A,一个模式串B,如果文本串含有模式串B,那么就能组合成多种意思,如下:

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”.

题解:

多校的官方题解,我们队当时做也是这样的思路,不过我没用KMP,暴力匹配一样也才15ms,数据比较水

1001  Another Meaning

对于这个问题,显然可以进行DP:

令dp[i]表示到i结尾的字符串可以表示的不同含义数,那么考虑两种转移:

末尾不替换含义:dp[i - 1]

末尾替换含义:dp[i - |B|]  (A.substr(i - |B| + 1,|B|) = B)

那么对于末尾替换含义的转移,需要快速判断BB能不能和当前位置的后缀匹配,kmp或者hash判断即可。

复杂度:O(N)

 #include<bits/stdc++.h>
using namespace std;
const int N=1e5+,mod=1e9+;
char a[N],b[N];
int dp[N];
int main(){
int t,ic=;
scanf("%d",&t);
while(t--){
scanf("%s%s",a+,b+);
int lena=strlen(a+),lenb=strlen(b+);
memset(dp,,sizeof(dp)),dp[]=;
for(int i=;i<=lena;i++){
dp[i]=(dp[i]+dp[i-])%mod;
int fg=;
if(lena-i+>=lenb)for(int j=;j<=lenb;j++){
if(a[i+j-]!=b[j])break;
if(j==lenb)fg=;
}
if(fg)dp[i+lenb-]=(dp[i+lenb-]+dp[i-])%mod;
}
printf("Case #%d: %d\n",ic++,dp[lena]);
}
return ;
}

hdu_5763_Another Meaning(dp)的更多相关文章

  1. HDU 5763 Another Meaning dp+字符串hash || DP+KMP

    题意:给定一个句子str,和一个单词sub,这个单词sub可以翻译成两种不同的意思,问这个句子一共能翻译成多少种不能的意思 例如:str:hehehe   sub:hehe 那么,有**he.he** ...

  2. Maximum Subarray 解答

    Question Find the contiguous subarray within an array (containing at least one number) which has the ...

  3. HDU 5763 Another Meaning KMP+DP

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Another Meaning Time Limit: 2000/1000 MS (Java/ ...

  4. HDU 5763 Another Meaning (kmp + dp)

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

  5. TTTTTTTTTTTTTT hdu 5763 Another Meaning 哈希+dp

    Another Meaning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. [HDOJ5763]Another Meaning(KMP, DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意:给定两个字符串a和b,其中a中的字符串如果含有子串b,那么那部分可以被替换成*.问有多少种 ...

  7. HDU5763 another meaning -(KMP+DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5763 思路:dp[i]表示前i个字符组成的字符串所表示的意思数量,则当匹配时dp[i]=dp[i-1] ...

  8. Another Meaning (KMP + DP)

    先用KMP重叠匹配求出各个匹配成功的尾串位置.然后利用DP去求,那转移方程应该是等于 上一个状态 (无法匹配新尾巴) 上一个状态 + 以本次匹配起点为结尾的状态(就是说有了新的位置) + 1 (单单一 ...

  9. HDU 5763 Another Meaning(DP+KMP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5763 题意: 给出一个字符串和一个模式串,模式串有两种意思,问这句话有几种意思. 思路:因为肯定要去字符串去找模 ...

随机推荐

  1. 安装webstrom,免激活长久使用

    1.在jetbrain官网下载最新版webstrom, 2.安装webstrom,不建议安装在c盘 3.安装时选择试用三十天 接下来就很重要: 首先将系统时间改到未来的某天,或者你未来写不动代码的一天 ...

  2. javaWEB总结(13):域对象的属性操作

    前言 本文主要讲解javaweb的四个域对象以及他们的作用范围,后面会有小demo来具体测试. 四个域对象 (1)pageContext:属性的作用范围仅限于当前JSP页面: (2)request:属 ...

  3. ActionBar之style出现Cannot resolve symbol 'Theme' 错误

    今天 2014/03/08 00:49 刚刚升级 android studio 到了 0.5.0 版本,修复了许多 bug,包含当前这个问题,之前一直困扰我很久,莫名奇妙的提示主题样式找不到,无法解析 ...

  4. 关于css3中transform的理解(只是改变状态未改变其真正的属性)

    众所周知,在css3中可以用animation实现动画效果,在这里用一个transform:translateX举例. <div class="div1"></d ...

  5. 数据库DateTime类型为空的处理

    一,写一个辅助类,将该方法设为静态,先装换为object,在转为DateTime,返回DateTime public class DateTimeHelper { public static Date ...

  6. EMPTY isset unset var_dump 用法

    empty    判断一个变量是否为空,返回布尔值  isset  isset 判断一个值是否存在  unset取消变量设置, var_dump 打印变量并类型

  7. screen 对象当当获取屏幕而已 innethtml可以知道调整屏幕宽度

    <div id='lidepeng' style="height: 100px;width: 100px;"></div><script type=& ...

  8. 认识System,System32,Syswow64

    有时候人们怀疑一个系统的底层结构能否保证这个系统在被使用时达到安全而高效,64位版本的Windows在这方面就比较完美.Windows XP和Windows Server 2003都是运行64位硬件的 ...

  9. mysql 登录中用户管理

    管理员账号 root 新增普通用户 修改root密码

  10. ftp资源调用迅雷下载

    <script src='http://pstatic.xunlei.com/js/webThunderDetect.js'></script> <script src= ...