POJ 2250--Compromise(LCS以及路径记录)
来源:互联网 发布:exp导出数据库lrm00108 编辑:程序博客网 时间:2024/04/25 02:44
来源:http://poj.org/problem?id=2250
题意:求最长公共子序列,并记录路径。
#include<iostream>#include<algorithm>#include<iomanip>#include<cstring>#include<string>#include<cstdio>#include<cmath>#include<queue>#include<map>#include<set>using namespace std;string ans[1005];int dp[1005][1005];string x[1005],y[1005];int path[1005][1005];int xx,yy;int t;void lcs(int i,int j){ if(i==0||j==0) { return ; } if(path[i][j]==0) { ans[t++]=x[i-1]; lcs(i-1,j-1); } else if(path[i][j]==1) { lcs(i,j-1); } else lcs(i-1,j);}int main(){ string a; while(cin>>a) { xx=0,yy=0; if(a=="#") goto B; else x[xx++]=a; t=0; while(getline(cin,a)&&a!="#") { string cur=""; for(int i=0;i<a.size();i++) { if(a[i]!=' ') cur+=a[i]; else { x[xx++]=cur; cur=""; } } x[xx++]=cur; }B: string b; while(getline(cin,b)&&b!="#") { string cur=""; for(int i=0;i<b.size();i++) { if(b[i]!=' ') cur+=b[i]; else { y[yy++]=cur; cur=""; } } y[yy++]=cur; } for(int i=1;i<=xx;i++) { for(int j=1;j<=yy;j++) { if(x[i-1]==y[j-1]) { path[i][j]=0; dp[i][j]=dp[i-1][j-1]+1; } else { dp[i][j]=max(dp[i][j-1],dp[i-1][j]); path[i][j]=dp[i][j-1]>dp[i-1][j]?1:2; } } } int tot=dp[xx][yy]; lcs(xx,yy); for(int i=t-1;i>=0;i--) { cout<<ans[i]<<" "; } cout<<endl; }return 0;}
- POJ 2250--Compromise(LCS以及路径记录)
- poj 2250 Compromise 记录路径的lcs
- poj 2250 Compromise (DP-LCS 记录路径)
- poj 2250 Compromise dp lcs 路径输出
- Poj 2250 Compromise【LCS+路径输出】
- POJ 2250 Compromise (线性dp LCS +递归路径)
- poj2250 Compromise dp lcs 记录路径
- POJ 2250 Compromise(LCS问题)
- poj 2250 Compromise (LCS)
- poj 2250 Compromise(LCS)
- poj 2250 Compromise(裸LCS DP)
- poj-2250Compromise(LCS+标记数组)
- 动态规划(LCS)(POJ 2250 Compromise)
- POJ 1015 Jury Compromise DP+记录路径
- pku 2250 Compromise(LCS)
- Pku oj 2250 Compromise(LCS+打印路径)
- poj 2250 Compromise(LCS,最长公共子序列)
- POJ 2250 Compromise(最长公共子序列LCS)
- 让家中电脑上的项目被互联网上用户访问
- 多线程编程
- SQL分页查询语句
- ♂天天向上--9.3
- c#高级
- POJ 2250--Compromise(LCS以及路径记录)
- 面向对象:三个特征:封装,继承,多态。
- java 定时器实现
- JAVA语言的特点
- 装饰模式
- 编写Android自定义按钮
- 控制台界面控制(二):清屏
- jquery控制div的滑动隐藏和显示
- 通讯程序