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 string c 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''.
Input
Input file contains several test cases (no more than 20). Process to the end of file.
Each test case contains three strings a, b and c (the length of each string is between 1 and 2000).
Output
For each test case, print ``Yes'', if c is a combine string of a and b , otherwise print ``No''.
Sample Input
abc
def
adebcf
abc
def
abecdf
Sample Output
Yes
No
思路:dp[i][j]表示第一个字符串用了前i个位置(第i个位置已匹配),第二个字符串的前j个位置(第j个位置已匹配)
是否可以对c串成功匹配(成功匹配则必然会匹配到c串的前i+j个位置)。
dp[i][j]==1则表示可以成功匹配
dp[i][j]==0则表示无法成功匹配
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=;
int dp[maxn][maxn];
int main()
{
string a,b,c;
while(cin>>a>>b>>c){
memset(dp,,sizeof(dp));
if(c.size()!=a.size()+b.size())
printf("No\n");
else{
dp[][]=;
for(int i=;i<=a.size();i++){
for(int j=;j<=b.size();j++){
if(a[i]==c[i+j]){
dp[i+][j]|=dp[i][j];
}
if(b[j]==c[i+j]){
dp[i][j+]|=dp[i][j];
}
}
}
if(dp[a.size()][b.size()]==){
printf("Yes\n");
}else{
printf("No\n");
}
}
}
return ;
}

hdu5707-Combine String(DP)的更多相关文章

  1. CodeForces - 710E Generate a String (dp)

    题意:构造一个由a组成的串,如果插入或删除一个a,花费时间x,如果使当前串长度加倍,花费时间y,问要构造一个长度为n的串,最少花费多长时间. 分析:dp[i]---构造长度为i的串需要花费的最短时间. ...

  2. HDU 5707 Combine String (DP,LCS变形)

    题意:给定三个字符串,问你第三个是不是由第一个和第二个组成的. 析:当时比赛是没有做出来啊...一直WA,就是没有判断长度,第一个和第二个和是不是和第三个一样,这个忘记... 我们用d[i][j]表示 ...

  3. hdu 4055 Number String(dp)

    Problem Description The signature of a permutation is a string that is computed as follows: for each ...

  4. HDU4055 - number string(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4055 思路:dp[i][j]表示处理前i个字符以j结尾可能的序列数. 当a[i]=='I'时,dp[i ...

  5. Educational Codeforces Round 16 E. Generate a String (DP)

    Generate a String 题目链接: http://codeforces.com/contest/710/problem/E Description zscoder wants to gen ...

  6. Number String(DP)

    题目: 题意: 给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1]. 比如排列 {3, 1, 2, 7, ...

  7. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  8. 【CF1132F】Clear the String(动态规划)

    [CF1132F]Clear the String(动态规划) 题面 CF 题解 考虑区间\(dp\). 增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了. #include<io ...

  9. 最长公共子序列长度(dp)

    /// 求两个字符串的最大公共子序列长度,最长公共子序列则并不要求连续,但要求前后顺序(dp) #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. Codeforces Round #513 总结

    首次正式的$Codeforces$比赛啊,虽然滚粗了,然而终于有$rating$了…… #A  Phone Numbers 签到题,然而我第一次写挂了(因为把11看成8了……) 只需要判断一下有多少个 ...

  2. n98-magerun2.phar

    installl: 1,cd /usr/local/bin && curl -O https://files.magerun.net/n98-magerun2.phar 2,chmod ...

  3. MT【314】正切比值

    (05复旦)已知三角形$\Delta ABC$满足$\tan A:\tan B:\tan C=1:2:3$,求$\dfrac{AC}{AB}$____ 解答:设$x=tan A$,利用恒等式$\tan ...

  4. AHOI2019N省联考凉凉记

    博主并未时空穿越,本文没有对选手造成恐慌 DAY0 这已经是我第四次省选了,时间真快啊,怀念三年前毫无压力的省选,考完以后如果有时间并且没退役的话可能会陆续搬以前写在别处的游记(主要是2018年的游记 ...

  5. SpringCloud笔记五:Feign

    目录 什么是Feign? 有了Ribbon我还要Feign干嘛? 新建consumer-feign 修改api项目 引入Maven文件 新建feign的接口 启动项目 报错 发泄发泄心情,一个段落 什 ...

  6. JavaScript 日期和时间基础知识

    前言 学习Date对象之前,首先要先了解关于日期和时间的一些知识.比如,闰年.UTC等等.深入了解这些,有助于更好地理解javascript中的Date对象. 标准时间 一般而言的标准时间是指GMT和 ...

  7. SpringBoot系列: Spring项目异常处理最佳实践

    ===================================自定义异常类===================================稍具规模的项目, 一般都要自定义一组异常类, 这 ...

  8. 使用ZooKeeper协调多台Web Server的定时任务处理(方案2)

    承接上个博文, 这次是方案2的实现, 本方案的特点:1. 该方案能很好地从几台服务器中选出一个Master机器, 不仅仅可以用于定时任务场景, 还可以用在其他场景下. 2. 该方案能实现Master节 ...

  9. [物理学与PDEs]第5章第4节 本构方程 - 应力与变形之间的关系

    5. 4 本构方程 - 应力与变形之间的关系 5.4.1. 本构关系的一般形式 1. 若 Cauchy 应力张量 ${\bf T}$ 满足 $$\bex {\bf T}({\bf y})=\hat{\ ...

  10. shell使用lftp连接ftp和sftp,并可以指定私钥

    lftp连接ftp在脚本中可以 lftp -c "open username:password@host:port; ls /Friso/20180822/click/mobile/SUCC ...