Codeforces10D(最长公共上升子序列+路径打印)很水的最长上升公共子序列+路径打印
来源:互联网 发布:怪物猎人x网络联机 编辑:程序博客网 时间:2024/06/05 14:17
很水的最长上升公共子序列+路径打印
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespace std;typedef long long lld;const int oo=0x3f3f3f3f;const lld OO=1LL<<61;const lld MOD=1000000007;#define eps 1e-6#define maxn 505int dp[maxn][maxn];int path[maxn][maxn];int a[maxn],b[maxn];int n,m;void dfs(int x){ if(path[n][x]==-1) { printf("%d",b[x]); return ; } dfs(path[n][x]); printf(" %d",b[x]);}int main(){ while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&m); for(int i=1;i<=m;i++) scanf("%d",&b[i]); memset(dp,0,sizeof dp); memset(path,-1,sizeof path); for(int i=1;i<=n;i++) { int pos=-1,Max=0; for(int j=1;j<=m;j++) { dp[i][j]=dp[i-1][j]; path[i][j]=path[i-1][j]; if(a[i]==b[j]&&dp[i][j]<Max+1) { dp[i][j]=Max+1; path[i][j]=pos; } if(a[i]>b[j]&&dp[i-1][j]>Max) { Max=dp[i-1][j]; pos=j; } } } int ans=1; for(int i=1;i<=m;i++) if(dp[n][ans]<dp[n][i]) ans=i; printf("%d\n",dp[n][ans]); if(dp[n][ans])dfs(ans); puts(""); } return 0;}/***/
0 0
- Codeforces10D(最长公共上升子序列+路径打印)很水的最长上升公共子序列+路径打印
- uva10051(最长上升子序列 + 路径打印)
- 最长公共子序列+打印路径
- 最长公共子序列打印路径
- CodeForces 10D. LCIS 最长公共上升子序列模板题 + 打印路径
- 【poj 2127】Greatest Common Increasing Subsequence 最长公共上升子序列lics+路径打印
- 最长公共上升子序列
- 最长公共上升子序列
- 最长上升公共子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共上升子序列
- 最长公共子上升序列
- 最长公共上升子序列
- Microsoft Office 家族甘特图 和 第三方甘特图软件
- Android本地音乐播放
- IOS-应用程序设置
- STM32的RCC配置
- 基于GLT法的风云三号气象卫星校正
- Codeforces10D(最长公共上升子序列+路径打印)很水的最长上升公共子序列+路径打印
- POJ2253 - Frogger
- Invalid Image Path问题
- Unity3D学习之(数据库的基本操作)
- C语言中EOF的意思
- 低功耗蓝牙4.0BLE编程-nrf51822开发(2)
- CXode 6.1 "" is not on any development teams
- 2014-12-8
- 进制之间的转换