POJ 2241 The Tower of Babylon(UVA 437)
来源:互联网 发布:linux下载命令 wget 编辑:程序博客网 时间:2024/06/05 07:44
多种方法,我用DP做的。
我当成的 最长下降子序列做的。 问了下其他人,有树形DP的,有差分约束用最短路的。
还有当作 二维的背包问题的。
最长单调子序列,长宽高 x,y,z 分别枚举成六个。然后排序,找最长单调子序列即可。
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<bitset>#include<vector>#include<cmath>#define INF 0x7fffffff#define eps 1e-8#define LL long long#define PI 3.141592654#define CLR(a,b) memset(a,b,sizeof(a))#define FOR(i,a,b) for(int i=a;i<b;i++)#define FOR_(i,a,b) for(int i=a;i>=b;i--)#define pub push_back#define puf push_front#define pob pop_back#define pof pop_front#define mp make_pair#define ft first#define sd second#define sf scanf#define pf printf#define sz(v) ((int)(v).size())#define all(v) (v).begin(),(v).end()#define acfun std::ios::sync_with_stdio(false)#define SIZE 200 +1using namespace std;struct point{ int x,y,z; void init(int xx,int yy,int zz) { x=xx,y=yy,z=zz; } friend bool operator <(point a,point b) { if(a.x==b.x) { if(a.y==b.y) return a.z>b.z; return a.y>b.y; } return a.x>b.x; }}l[SIZE];int n;int dp[SIZE];int main(){ int cs=1; while(~sf("%d",&n),n) { int m=0; FOR(i,0,n) { int x,y,z; sf("%d%d%d",&x,&y,&z); l[m++].init(x,y,z); l[m++].init(x,z,y); l[m++].init(y,x,z); l[m++].init(y,z,x); l[m++].init(z,x,y); l[m++].init(z,y,x); } sort(l,l+m); CLR(dp,0); FOR(i,0,m) { FOR(j,i+1,m) { if(l[j].x<l[i].x&&l[j].y<l[i].y) dp[j]=max(dp[j],dp[i]+l[i].z); } } int ans=0; FOR(i,0,m) //pf("%d \n",dp[i]+l[i].z); ans=max(ans,dp[i]+l[i].z); pf("Case %d: maximum height = %d\n",cs++,ans); }}
0 0
- POJ 2241 The Tower of Babylon(UVA 437)
- UVA 437 (POJ 2241) The Tower of Babylon(DP)
- poj 2241 && uva 437 The Tower of Babylon(DP)
- uva 437 The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVA 437 The Tower of Babylon
- UVa 437 - The Tower of Babylon LIS
- uva 437 - The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVA 437 The Tower of Babylon
- UVa:437 The Tower of Babylon
- UVA - 437 The Tower of Babylon
- Uva-437 The Tower of Babylon DP
- uva 437 The Tower of Babylon
- UVA 437 The Tower of Babylon
- 排序算法(八)希尔排序(缩小增量排序)
- sql日期处理以及转换
- XML封装通信协议的方法
- 大数据技术收集
- AHK新手入门知识了解
- POJ 2241 The Tower of Babylon(UVA 437)
- 免费迅雷会员账号
- 初次接触HttpClient
- 改自雨果的小诗
- swift入门基础知识5字典
- Java内存溢出
- jquery select变化事件获取选择的值
- Oracle virtual box 如何实现主机和虚拟机之间的共享文件和操作系统全屏显示
- iOS 多个UIImageView 加载高清大图时的内存管理