POJ 2250 Compromise【LCS】+输出路径】的更多相关文章

POJ 2250 Compromise(LCS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/D 题目: Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulf…
题目链接: http://poj.org/problem?id=2250 Compromise Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9284   Accepted: 3972   Special Judge Description In a few months the European Currency Union will become a reality. However, to join the clu…
题目链接:https://vjudge.net/problem/POJ-2250 题目大意:给出n组case,每组case由两部分组成,分别包含若干个单词,都以“#”当结束标志,要求输出最长子序列. #include <iostream> #include <string> using namespace std; ], b[], ans[]; ][], num[][]; void LCSLength() { memset(dp, , sizeof(dp)); memset(num…
题目传送门 题意:求单词的最长公共子序列,并要求打印路径 分析:LCS 将单词看成一个点,dp[i][j] = dp[i-1][j-1] + 1 (s1[i] == s2[j]), dp[i][j] = max (dp[i-1][j], dp[i][j-1]) 代码: #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <strin…
题意:给你两个单词序列,求出他们的最长公共子序列. 多组数据输入,单词序列长度<=100,单词长度<=30 因为所有组成LCS的单词都是通过 a[i] == b[j] 更新的. 打印序列的时候用mark标记一下,然后回溯找就可以了. #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <map> #include <…
题目链接:http://poj.org/problem?id=2250 思路分析:最长公共子序列问题的变形,只是把字符变成了字符串,按照最长公共子序列的思路即可以求解. 代码如下: #include <stdio.h> #include <string.h> #define IsEqual(a, b) strcmp((a), (b)) == 0 enum { Left, Up, UpAndLeft }; int XLen, YLen; + ; ], Y[MAX_N][]; int…
Problem Description The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit into the genome of another one. Most times this method doesn't work, but sometimes, in very rare cases, a…
题目大意 题目不需要大意,poj居然还有中文题 鸣谢 特别鸣谢ljc大佬提供的方法!!! 解法 我们可能输出个最短路径的长度比较简单,但是输出最短路径真的是没有做过,这里有一种简单的方法 因为我们的dfs是把所有的情况都遍历了一遍,那么是不是我们的答案的路径就在这其中呢? 这样我们在判断条件的时候把老生常谈的那些什么路径数记录的变成如果sum<minn更新minn,然后记录这些路径 回溯的时候,这里dfs用了三个参数x,y,cur.把cur回溯顺便就回溯了路径 代码(为啥没有高亮...) #in…
hdu 1503 不知道最后怎么输出,因为公共部分只输出一次.有人说回溯输出,感觉好巧妙!其实就是下图,输出的就是那条灰色的路径,但是初始时边界一定要初始化一下,因为最第一列只能向上走,第一行只能向左走.我用1表示向上走,2向左上方走,3向左走. 刚开始输入字符串时有两种方法,直接输入:或从地址后一位输入,即此时数组起始编号为1.直接输入时,dp[i][j]表示的是以s1[i-1],s2[j-1]为结尾LCS,另一种则就是表示以s1[i],s2[j]为结尾的LCS.两者在路径输出时有些差别,以前…
题意:有两个字符串,求他们的最长公共子序列并输出. 题解:首先跑个LCS记录一下dp数组,然后根据dp数组来反着还原路径,只有当两个位置的字符相同时才输出. 代码: char s[N],t[N]; int dp[10000][10000]; int main() { //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); scanf("%s %s",s+1,t+1); int len1=strlen(s+1); int len2=st…