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…
题意:给你两个单词序列,求出他们的最长公共子序列. 多组数据输入,单词序列长度<=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 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…
题目传送门 题意:求单词的最长公共子序列,并要求打印路径 分析: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…
题目链接: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…
题目链接: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…
LCS问题.基金会DP. 我很伤心WA非常多.就在LCS问题,需要记录什么路. 反正自己的纪录path错误,最后,就容易上当. 没有优化,二维阵列,递归打印,cin.eof() 来识别 end of file 标识. 至于单词用map 映射的. 事实上也用不着,直接二维string或者 二维char 然后strcmp 也行. Special Judge 交 UVA 531 奇怪的PE了. .. 然后改成 flag 标记 输出 空格.最终都AC了. #include<cstdio> #inclu…
题目大意 给定两段文本,问公共单词有多少个 题解 裸LCS... 代码: #include<iostream> #include<string> using namespace std; #define MAXN 105 string x[MAXN],y[MAXN]; int path[MAXN][MAXN],dp[MAXN][MAXN]; int n,m; void work() { ; i<=n; i++) dp[i][]=; ; j<=m; j++) dp[][j…
题目字符串的LCS,输出解我比较不会,dp的时候记录从哪里转移来的,之后要一步一步转移回去把解存起来然后输出. #include<cstdio> #include<cstring> #define N 102 #define M 32 int n,m,dp[N][N],ans[N][N]; char s1[N][M],s2[N][M],str[N][M]; void solve(){ memset(dp,0,sizeof dp); memset(ans,0,sizeof ans);…
compromise Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description In a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is…