题目链接: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. Debian系Linux的dpkg命令

    dpkg "是"Debian Packager "的简写.为 "Debian" 专门开发的套件管理系统,方便软件的安装.更新及移除.所有源自" ...

  2. iOS蓝牙开发

    蓝牙常见名称和缩写 MFI ======= make for ipad ,iphone, itouch 专们为苹果设备制作的设备 BLE ==== buletouch low energy,蓝牙4.0 ...

  3. .net webapi项目中支持session

    webapi中默认是不支持session的开启的 需要在Global.asax文件中,添加如下代码 public override void Init() { this.PostAuthenticat ...

  4. Struts2-1.配置&与第一个应用

    配置流程 1.web项目中导入Strus2应用需要的包,复制到项目的lib文件夹下 点击此处下载需要的包,解压后复制进去即可:http://pan.baidu.com/s/1jHhjd2Y 2.编写S ...

  5. js实例--js滚动条缓慢滚动到顶部

    收集篇(已测)-- <html><head> <script type="text/javascript"> var currentPositi ...

  6. 遮盖层实现(jQuery+css+html)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. 【Python】关于Python有意思的用法

    开一篇文章,记录关于Python有意思的用法,不断更新 1.Python树的遍历 def sum(t): tmp=0 for k in t: if not isinstance(k,list): tm ...

  8. jQuery Post 提交内容中有标签报错

    Post编辑一点内容要传后台数据库: var html = editor2.html() console.log(encodeURIComponent(html)); //console.log(&q ...

  9. Java 序列化 transient关键字

    Java 序列化 transient关键字 @author 敏敏Alexia 转自:http://www.cnblogs.com/lanxuezaipiao/p/3369962.html 1. tra ...

  10. hdu_5898_odd-even number(数位DP)

    题目链接:hdu_5898_odd-even number 题意: 给你一个区间,问你这个区间中满足连续的偶数的位数为奇数,连续的奇数的位数是偶数的个数 题解: 设dp[i][j][k][l]为考虑当 ...