*【HDU - 5707】Combine String(dp)

题干:

Given three strings aa, bb and cc, your mission is to check whether cc is the combine string of aa and bb. 
A string cc is said to be the combine string of aa and bb if and only if cc can be broken into two subsequences, when you read them as a string, one equals to aa, and the other equals to bb. 
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 aa, bb and cc (the length of each string is between 1 and 2000). 

Output

For each test case, print ``Yes'', if cc is a combine string of aa and bb, otherwise print ``No''. 

Sample Input

abc
def
adebcf
abc
def
abecdf

Sample Output

Yes
No

解题报告:

  可以直接bool类型的dp[i][j]代表第一个串前i个和第二个串前j个可否匹配的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
char a[MAX],b[MAX],c[MAX];
bool dp[2222][2222];
int main()
{while(~scanf("%s%s%s",a+1,b+1,c+1)) {int la = strlen(a+1);int lb = strlen(b+1);int lc = strlen(c+1);if(la+lb!=lc) {puts("No");continue;}memset(dp,0,sizeof dp);dp[0][0]=1;for(int i = 1; i<=la; i++) if(c[i] == a[i]) dp[i][0] |= dp[i-1][0];for(int i = 1; i<=lb; i++) if(c[i] == b[i]) dp[0][i] |= dp[0][i-1]; for(int i = 1; i<=la; i++) {for(int j = 1; j<=lb; j++) {if(c[i+j] == a[i]) dp[i][j] |= dp[i-1][j];if(c[i+j] == b[j]) dp[i][j] |= dp[i][j-1];}}if(dp[la][lb]) puts("Yes");else puts("No");}return 0 ;
}

 

但是比赛的时候硬是让我写了个序列自动机+dp。

dp[i][j]代表第一个串前i个和第二个串前j个匹配,需要达到的最小位置。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2000 + 5;
char a[MAX],b[MAX],c[MAX];
int dp[MAX][MAX],trie[MAX][222];
int main()
{while(~scanf("%s",a+1)) {		scanf("%s",b+1);scanf("%s",c+1);memset(dp,0x3f,sizeof dp);dp[0][0]=0;int la = strlen(a+1),lb = strlen(b+1),lc = strlen(c+1); if(la+lb!=lc) {puts("No");continue;}for(int i = 0; i<=129; i++) trie[lc+1][i]=trie[lc+2][i] = lc+1;for(int i = lc; i>=1; i--) {int cur = c[i] ;for(int j = 0; j<129; j++) {if(j == cur) trie[i][j] = i;else trie[i][j] = trie[i+1][j];}}for(int i = 1; i<=la; i++) dp[i][0] = trie[dp[i-1][0]+1][a[i]];for(int i = 1; i<=lb; i++) dp[0][i] = trie[dp[0][i-1]+1][b[i]];for(int i = 1; i<=la; i++) {for(int j = 1; j<=lb; j++) {dp[i][j] = min(dp[i][j],trie[dp[i-1][j]+1][a[i]]);dp[i][j] = min(dp[i][j],trie[dp[i][j-1]+1][b[j]]);}}if(dp[la][lb] != lc) puts("No");else puts("Yes");}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440330.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《TCP/IP详解》学习笔记(一):基本概念

为什么会有TCP/IP协议 在世界上各地&#xff0c;各种各样的电脑运行着各自不同的操作系统为大家服务&#xff0c;这些电脑在表达同一种信息的时候所使用的方法是千差万别。就好像圣经中上帝打乱 了各地人的口音&#xff0c;让他们无法合作一样。计算机使用者意识到&#xff0c;…

【POJ - 3272】Cow Traffic(dp,建反向图,DAG拓扑图)

题干&#xff1a; The bovine population boom down on the farm has caused serious congestion on the cow trails leading to the barn. Farmer John has decided to conduct a study to find the bottlenecks in order to relieve the traffic jams at milking time. The…

pc服务器不同型号,服务器与PC系统软件之不同

服务器与PC系统软件之不同对于中关村在线的网友来说&#xff0c;PC系统应该都不陌生&#xff0c;而且分分钟重装的水准。但在笔者过往的服务器装机经验中&#xff0c;可谓是一部千年血泪史。服务器和PC系统差别还是很大的。现在的PC系统多是windows7和windows10&#xff0c;而在…

9.XGBoost

本教程是机器学习系列的一部分。 在此步骤中&#xff0c;您将学习如何使用功能强大的xgboost库构建和优化模型。 What is XGBoost XGBoost是处理标准表格数据的领先模型&#xff08;您在Pandas DataFrames中存储的数据类型&#xff0c;而不是像图像和视频这样的更奇特的数据类…

*【HDU - 5711】Ingress(tsp旅行商问题,优先队列贪心,状压dp,floyd最短路,图论)

题干&#xff1a; Brickgao, who profited from your accurate calculating last year, made a great deal of money by moving bricks. Now he became gay shy fool again and recently he bought an iphone and was deeply addicted into a cellphone game called Ingress. …

ajax get请求成功,成功()函数的AJAX GET请求

后不叫我有一个jQuery的AJAX脚本像下面&#xff1a;成功()函数的AJAX GET请求function FillCity() {var stateID $("#ddlState").val();$.ajax({url: Url.Action("Employee", "Index"),type: "GET",dataType: "json",data:…

《TCP/IP详解》学习笔记(二):数据链路层

数据链路层有三个目的&#xff1a; 为IP模块发送和 接收IP数据报。为ARP模块发送ARP请求和接收ARP应答。为RARP发送RARP请 求和接收RARP应答ip大家都听说过。至于ARP和RARP&#xff0c;ARP叫做地址解析协议&#xff0c;是用IP地址换MAC地址的一种协议&#xff0c;而RARP则叫…

【POJ - 2762】Going from u to v or from v to u?(Tarjan缩点,树形dp 或 拓扑排序,欧拉图相关)

题干&#xff1a; In order to make their sons brave, Jiajia and Wind take them to a big cave. The cave has n rooms, and one-way corridors connecting some rooms. Each time, Wind choose two rooms x and y, and ask one of their little sons go from one to the o…

《TCP/IP详解》学习笔记(三):IP协议、ARP协议

把这三个协议放到一起学习是因为这三个协议处于同一层,ARP 协议用来找到目标主机的 Ethernet 网卡 Mac 地址,IP 则承载要发 送的消息。数据链路层可以从 ARP 得到数据的传送信息,而从 IP 得到要传输的数据信息。 IP 协议 IP 协议是 TCP/IP 协议的核心,所有的 TCP,UDP,IMCP,IGCP…

光与夜之恋服务器维护中,光与夜之恋7月16日停服维护说明 维护详情一览

光与夜之恋7月16日停服维护说明维护详情一览。光与夜之恋7月16日停服维护更新了哪些内容?我们去了解一下。【7月16日停服维护说明】亲爱的设计师&#xff1a;为了给设计师们提供更好的游戏体验&#xff0c;光启市将于7月16日(周五)00:00进行预计5小时的停服维护&#xff0c;可…

10.Partial Dependence Plots

本教程是ML系列的一部分。 在此步骤中&#xff0c;您将学习如何创建和解释部分依赖图&#xff0c;这是从模型中提取洞察力的最有价值的方法之一。 What Are Partial Dependence Plots 有人抱怨机器学习模型是黑盒子。这些人会争辩说我们无法看到这些模型如何处理任何给定的数据…

springboot监控服务器信息,面试官:聊一聊SpringBoot服务监控机制

目录前言任何一个服务如果没有监控&#xff0c;那就是两眼一抹黑&#xff0c;无法知道当前服务的运行情况&#xff0c;也就无法对可能出现的异常状况进行很好的处理&#xff0c;所以对任意一个服务来说&#xff0c;监控都是必不可少的。就目前而言&#xff0c;大部分微服务应用…

0.《Apollo自动驾驶工程师技能图谱》

【新年礼物】开工第一天&#xff0c;送你一份自动驾驶工程师技能图谱&#xff01; 布道团队 Apollo开发者社区 1月 2日 AI时代到来&#xff0c;人才的缺乏是阻碍行业大步发展的主要因素之一。Apollo平台发布以来&#xff0c;我们接触到非常多的开发者他们并不是专业自动驾驶领…

【HDU - 1116】【POJ - 1386】Play on Words(判断半欧拉图,欧拉通路)

题干&#xff1a; Some of the secret doors contain a very interesting word puzzle. The team of archaeologists has to solve it to open that doors. Because there is no other way to open the doors, the puzzle is very important for us. There is a large number…

11.Pipelines

本教程是ML系列的一部分。 在此步骤中&#xff0c;您将了解如何以及为何使用管道清理建模代码。 What Are Pipelines 管道是保持数据处理和建模代码有序的简单方法。 具体来说&#xff0c;管道捆绑了预处理和建模步骤&#xff0c;因此您可以像使用单个包一样使用整个捆绑包。…

ubuntu服务器创建共享文件夹,Ubuntu samba安装创建共享目录及使用

Ubuntu samba更新了很多版本更新&#xff0c;我本人认为Ubuntu samba是很好使的文件系统&#xff0c;在此向大家推荐。如今技术不断更新&#xff0c;各种使用文件都已经淘汰。我认为还是有很不错的如Ubuntu samba值得大家来运用。一. Ubuntu samba的安装:sudo apt-get insall s…

【POJ - 2337】Catenyms(欧拉图相关,欧拉通路输出路径,tricks)

题干&#xff1a; A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms: dog.gophergopher.ratrat.tigeraloha.alohaarachnid.dog A…

12.Cross-Validation

本教程是ML系列的一部分。 在此步骤中&#xff0c;您将学习如何使用交叉验证来更好地衡量模型性能。 What is Cross Validation 机器学习是一个迭代过程。 您将面临关于要使用的预测变量&#xff0c;要使用的模型类型&#xff0c;提供这些模型的参数等的选择。我们通过测量各…

服务器不显示u盘,服务器不读u盘启动

服务器不读u盘启动 内容精选换一换介绍使用Atlas 200 DK前需要准备的配件及开发服务器。Atlas 200 DK使用需要用户提前自购如表1所示配件。准备一个操作系统为Ubuntu X86架构的服务器&#xff0c;用途如下&#xff1a;为Atlas 200 DK制作SD卡启动盘。读卡器或者Atlas 200 DK会通…

【FZU - 2039】Pets(二分图匹配,水题)

题干&#xff1a; 有n个人&#xff0c;m条狗&#xff0c;然后会给出有一些人不喜欢一些狗就不会购买&#xff0c;问最多能卖多少狗。。 Input There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the fir…