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 ;
}

最新文章

  1. 编写高质量代码:改善Java程序的151个建议(第6章:枚举和注解___建议88~92)
  2. oracle中批量生成字段类型的脚本
  3. lodop打印控件
  4. Connect教程系列--响应式布局(一)
  5. css实现文字过长省略显示
  6. Java程序员面试宝典——重要习题整理
  7. java 迭代器iterator
  8. 如何在Eclipse中快速添加main方法
  9. 【php-fpm】启动PHP报错ERROR: [pool www] cannot get uid for user &#39;apache&#39;
  10. 类与对象 &amp;&amp; 继承
  11. 【NLP】分词 新词
  12. AVD Manager 模拟器使用
  13. docker搭建rabbitmq
  14. 【小白的CFD之旅】21 网格划分软件的选择
  15. Ubuntu 添加,删除ppa
  16. matplotlib 散点图scatter
  17. express 调优的一个过程和心得,不错的文章
  18. 【python】 time模块和datetime模块详解 【转】
  19. 欧拉函数phic以及超大数的快速幂
  20. [BZOJ5250][九省联考2018]秘密袭击(DP)

热门文章

  1. Django 视图系统
  2. Windows 7 下安装 docker 应用容器引擎
  3. 洛谷 P3380 【【模板】二逼平衡树(树套树)】
  4. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )
  5. Linux设备树(六 memory&amp;chosen节点)
  6. 20175209 《Java程序设计》第五周学习总结
  7. oldboy s21day10
  8. [物理学与PDEs]第4章第3节 一维反应流体力学方程组 3.3 一维反应流体力学方程组的数学结构
  9. [物理学与PDEs]第1章第8节 静电场和静磁场 8.1 静电场
  10. UE导航系统详