hdu 5707 Combine String dphen dp
来源:互联网 发布:手机淘宝链接怎么弄 编辑:程序博客网 时间:2024/06/01 23:06
Combine String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2210 Accepted Submission(s): 624
Problem Description
Given three strings a , b and c , your mission is to check whether c is the combine string of a and b .
A stringc is said to be the combine string of a and b if and only if c can be broken into two subsequences, when you read them as a string, one equals to a , and the other equals to b .
For example, ``adebcf'' is a combine string of ``abc'' and ``def''.
A string
For example, ``adebcf'' is a combine string of ``abc'' and ``def''.
Input
Input file contains several test cases (no more than 20). Process to the end of file.
Each test case contains three stringsa , b and c (the length of each string is between 1 and 2000).
Each test case contains three strings
Output
For each test case, print ``Yes'', if c is a combine string of a and b , otherwise print ``No''.
Sample Input
abcdefadebcfabcdefabecdf
Sample Output
YesNo
很屌丝的题。。
看到的第一眼暴力while走了一遍。。
贪心思想觉得没毛病啊///可是真的有毛病啊。。。
wa了4发。。
得到一组数据
ab
abc
aabcb
abc
ab
aabcb
两个都是Yes
贪心会有一个No
果断dp
dp【i】【j】
i是s1 的某个
j是s2
if(s1[i]==s[i+j]) dp[i+1][j]|=dp[i][j]; if(s2[j]==s[i+j]) dp[i][j+1]|=dp[i][j];
#include<stdio.h>#include<string.h>int dp[2003][2003];char s[2003];char s1[2003];char s2[2003];int main(){ while(~scanf("%s %s %s",s1,s2,s)) { memset(dp,0,sizeof(dp)); int Flag=0; int len1=strlen(s1); int len2=strlen(s2); int len=strlen(s); dp[0][0]=1; for(int i=0;i<=len1;i++) { for(int j=0;j<=len2;j++) {if(s1[i]==s[i+j]) dp[i+1][j]|=dp[i][j]; if(s2[j]==s[i+j]) dp[i][j+1]|=dp[i][j];} } if(dp[len1][len2]&&len==len1+len2) printf("Yes\n"); else printf("No\n"); }}
阅读全文
0 0
- hdu 5707 Combine String dphen dp
- HDU 5707 Combine String (DP)
- hdu-5707-Combine String
- hdu 5707 Combine String
- HDU-5707-Combine String【2016CCPC女生专场】【DP】
- HDU 5707 Combine String(动态规划)
- Combine String
- DP 杭电女生赛07题 Combine String
- HDU "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场 Combine String
- Combine String模拟
- HDU 4681 String(DP)
- HDU 4681 String dp
- [DP]HDU 4055 Number String
- hdu String painter(dp)
- hdu 4681 String(dp)
- 简单dp-hdu-4681-String
- HDU 4055 Number String dp
- 【HDU】4681 String(DP)
- Maven+SpringMVC+Swagger整合
- javaseday21补充(装饰设计模式 BufferedReader 的小弟 LineNumber 行号媒体文件的复制)
- css实现内容超长自动截取并显示省略号
- ffmpeg.c源码阅读
- JAVA互联网学习之Filter
- hdu 5707 Combine String dphen dp
- 单元测试心得
- JS打开摄像头并截图上传示例
- MQ相关
- HDU 2602 Bone Collector (01背包)
- Spark R安装成功的步骤
- updateByPrimaryKeySelective和updateByPrimaryKey区别
- 初识微信小程序(一)
- 理解二叉树建立过程的例题