UVA 437 -- The Tower of Babylon
来源:互联网 发布:python是用来做什么的 编辑:程序博客网 时间:2024/06/18 06:48
题目大意: 给出n个长方形的长宽高,长宽高是可以互相转换的,由两个组成长方形的底部,另外一个是高度,把可能得到的长方体叠加在一起,求最高的高度,叠加的条件是上边的长方体的底部边长小于下面的长方体的底部的边长;
思路分析:把可能得到的长方体都存下来,把任意两个长方体能叠加在一起的连一条边,也就是建图的过程,然后对与每一个长方体进行搜索,找出一条最长的路径。
代码实现:
#include<cstdio>#include<cstring>#include<iostream>#define Min(a,b) ((a)<(b)?(a):(b))#define Max(a,b) ((a)>(b)?(a):(b))#define MEM(a) (memset((a),0,sizeof(a)))#define MEME(a) (memset((a),-1,sizeof(a)))#define MEMX(a) (memset((a),0x3f,sizeof(a)))using namespace std;const int N=100;int G[N][N],d[N],cnt;struct node{ int x,y,z;}rec[N];int dfs(int i){ int& ans=d[i]; if(ans>0) return ans; ans=rec[i].z; for(int j=0;j<cnt;++j){ if(G[i][j]) ans=Max(dfs(j)+rec[i].z,ans); } return ans;}int main(){ int n,xx,yy,zz; int Case=0; while(~scanf("%d",&n),n){ MEM(G),MEM(d); cnt=0; int max_h=-1; while(n--){ scanf("%d%d%d",&xx,&yy,&zz); rec[cnt].x=xx,rec[cnt].y=yy,rec[cnt++].z=zz; rec[cnt].x=xx,rec[cnt].y=zz,rec[cnt++].z=yy; rec[cnt].x=yy,rec[cnt].y=zz,rec[cnt++].z=xx; } for(int i=0;i<cnt;++i){ for(int j=0;j<cnt;++j){ if((rec[i].x<rec[j].x&&rec[i].y<rec[j].y)||(rec[i].x<rec[j].y&&rec[i].y<rec[j].x)) G[i][j]=1; } } for(int i=0;i<cnt;++i) max_h=Max(dfs(i),max_h); printf("Case %d: maximum height = %d\n",++Case,max_h); }}
0 0
- 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
- UVA 437 The Tower of Babylon | dp
- UVA 437 The Tower of Babylon
- UVA 437 The Tower of Babylon
- 第六章(8)求集合的幂集
- 第六章(9).四皇后问题
- 第四章(4).KMP算法
- 第四章(5).建立词索引表
- 第三章(8).离散事件模拟
- UVA 437 -- The Tower of Babylon
- 内存访问错误
- 请学好C语言![转]
- 学计算机必读[转]
- realloc重分配内存详解
- Static用法总结
- C语言中的输入输出函数总结
- linux后台进程实例
- 关于C语言中return的一些总结