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. 【JVM】JVM垃圾收集器、垃圾收集算法、无用对象

    Java 常见的垃圾收集器有哪些 实际上,垃圾收集器(GC,Garbage Collector)是和具体 JVM 实现紧密相关的,不同厂商(IBM.Oracle),不同版本的JVM,提供的选择也不同. ...

  2. ajax 跨域 springboot

    CORS 定义 Cross-Origin Resource Sharing(CORS)跨来源资源共享是一份浏览器技术的规范,提供了 Web 服务从不同域传来沙盒脚本的方法,以避开浏览器的同源策略,是 ...

  3. Wannafly挑战赛23 T2游戏 SG函数

    哎,被卡科技了,想了三个小时,最后还是大佬给我说是\(SG\)函数. \(SG\)函数,用起来很简单,证明呢?(不可能的,这辈子都是不可能的) \(SG\)定理 游戏的\(SG\)函数就是各个子游戏的 ...

  4. MySQL 导入导出数据库、表

    使用 GUI 软件很好操作,下面介绍命令行操作. 导出 cmd 命令 # 1.1 导出整个数据库 mysqldump -hlocalhost -uroot -p student_db > C:\ ...

  5. Python【pyyaml】模块

    pyyaml模块安装: pip install pyyaml pyyaml导入: import yaml pyyaml使用: 1.使用前,在pycharm中新建一个以yaml或yml结尾的文件,保存为 ...

  6. SQL server 统计数据库表数量和列出所有表名称

    统计表数量 SELECT count(*) FROM sys.objects WHERE type='U' 列出表名称  SELECT NAME  FROM sys.objects WHERE typ ...

  7. Pandas系列(十四)- 实战案例

    一.series import pandas as pd import string #创建Series的两种方式 #方式一 t = pd.Series([1,2,3,4,43],index=list ...

  8. LCA(Tarjan)

    时间复杂度:dfs为O(N),dfs过程中处理所有查询对为O(M),总时间复杂度O(N+M) #include<iostream> #include<cstdio> using ...

  9. 第十五节: EF的CodeFirst模式通过DataAnnotations修改默认协定

    一. 简介 1. DataAnnotations说明:EF提供以特性的方式添加到 domain classes上,其中包括两类:  A:System.ComponentModel.DataAnnota ...

  10. python 写代码笔记 2017.6.15

    其实并不是越复杂的代码越好,简单高效才是好. 关键是思路和逻辑,还有多看别人写的代码. 学习到了:)