【DP】UVA 103 Stacking Boxes 输出路径
来源:互联网 发布:淘宝宝贝复制大师 编辑:程序博客网 时间:2024/05/21 17:42
类似于叠箱子
对于箱子a : (a1,a2,a3),b : (b1,b2,b3)
存在一个顺序ai<bj,ak<bi,aj<bk 就表示a可以到b
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#include <set>#include <map>#define IN freopen ("in.txt" , "r" , stdin);#define OUT freopen ("out.txt" , "w" , stdout);typedef long long LL;const int MAXN = 1111111;//点数的最大值const int MAXM = 20006;//边数的最大值const int INF = 11521204;const int mod=1000000007;int n,m;struct node{ int x[44],num; friend bool operator < (const node&a, const node&b) { for(int i=0; i<m; ++i) { if(a.x[i]>b.x[i])return false; } return true; }} a[100];int dp[111];int x[111];void print(int i){ if(x[i]!=i)print(x[i]); printf("%d ", a[i].num);}int main(){ IN; while(scanf("%d%d",&n,&m)!=EOF) { memset(dp,0,sizeof(dp)); memset(x,0,sizeof(x)); dp[0]=1; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) scanf("%d",&a[i].x[j]); sort(a[i].x,a[i].x+m);//给维度排序 a[i].num=i+1;//编号 } sort(a,a+n);//全部排序 int maxx=1,ans=0; for(int i=0; i<n; i++) { for(int j=0; j<i; j++) { int flag=0; for(int k=0; k<m; k++)//flag==0表示i与j可叠加 { if(a[i].x[k]<=a[j].x[k]) flag=1; } if(!flag&&dp[i]<dp[j]+1) { dp[i]=dp[j]+1; x[i]=j; } if(dp[i]>maxx)//更新最大值 { maxx=dp[i]; ans=i;//起始 } } } printf("%d\n",maxx); print(ans);//输出序列 printf("\n"); } return 0;}
0 0
- 【DP】UVA 103 Stacking Boxes 输出路径
- uva 103 (dp)Stacking Boxes
- Stacking Boxes - UVa 103 dp
- uva--103Stacking Boxes +dp
- UVa 103 - Stacking Boxes (LIS,打印路径)
- UVa 103 Stacking Boxes (DP&DAG)
- UVA 103 Stacking Boxes 堆砌盒子(DP)
- UVA 103 Stacking Boxes (DP)
- UVa 103 Stacking Boxes
- UVA 103 - Stacking Boxes
- uva 103 - Stacking Boxes
- uva 103 Stacking Boxes
- [UVA 103] Stacking Boxes
- uva:103 - Stacking Boxes
- UVa 103 - Stacking Boxes
- UVA - 103 Stacking Boxes
- uva 103 - Stacking Boxes
- UVA 103 Stacking Boxes
- 【面试准备】最长公共子序列
- curl_slist_append增加http header -- curl
- 设计模式C++实现(15)——观察者模式
- AFNetworking2.0源码解析<一>
- C++: 实现一个简易的银行排号叫号系统
- 【DP】UVA 103 Stacking Boxes 输出路径
- 时间转换
- 唉。
- extern 较深入的用法-全局-静态
- 转:二叉树的深度优先遍历和广度优先遍历
- 数组的初始化
- VC++自定义消息的发送与接收的方法实现
- struts2 分页查询实例
- 要减肥吗?