题目链接: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. 线段树解决leetcode307. Range Sum Query - Mutable

    在下面的图中,求[0,0]和[1,1]区间元素和, 对于[0,0] start =0 ,end = 0, 查到root = 4 [0-1]的节点,mid = 0, 此时mid > end-1,表 ...

  2. winform上传文件

    //上传图片 文件 public int addUpPic( String strProCode,String strFileName,String strUpType) { //strFileNam ...

  3. final使用

    final修饰  基本数据类型时候   对应的 数据不能改变:::final修饰 对象类型 ,那么对应的引用地址不能改变(对象中的值可以改变): 如果final修改方法,那么该方法不能被子类重写 :: ...

  4. linux安装gcc-c++

    首先查看系统是否安装: gcc -v    g++ -v    c++ -v 没有安装则执行一键安装命令:#yum install gcc-c++ 如果直接执行:#yum install c++是安装 ...

  5. 第九十四节,html5+css3移动手机端流体布局,旅游部分,媒体查询

    html5+css3移动手机端流体布局,旅游部分,媒体查询 媒体查询 媒体查询是手机网站和自适应网站的重要部分,媒体查询可以根据不同的屏幕大小,做响应的处理,如文字的大小,区块隐藏等等 媒体查询,这里 ...

  6. 2016 SyScan360 国际前瞻信息安全会议 多角度探讨信息安全

    SyScan360国际前瞻信息安全会议由与中国第一大互联网安全公司-360公司与SyScan前瞻信息安全技术年会(TheSymposiumonSecurityforAsiaNetwork,以下简称Sy ...

  7. 如何使用cygwin去编译cocos2dx项目中的C++文件

    将生成的cocos2dx的Android项目导入到eclipse 可以先测试一下如何编译C++项目: 1.打开cygwin,进入到Android项目对应的目录下面去: 2.编译脚本 在编译脚本之间,如 ...

  8. Android启动另一个APP时,注意disable与enable的问题

    在写游戏sdk时候遇到了一个需要在sdk中通过scheme来启动支付宝的免密支付功能,所以需要在设备中通过包名检查一下支付宝是否存在. 此时遇到了一个问题,在三星设备中可以将app给处于disable ...

  9. CF #368 div2

    题目链接:http://codeforces.com/contest/707/problem/A A. Brain's Photos time limit per test 2 seconds mem ...

  10. 安卓请求服务器js文件下载到本地,版本号就下载

    <?phpreturn array('CJ_V' => 'v0.15',) <script src="/js/reserve.js?<?=C('CJ_V')?> ...