UVA 437 The Tower of Babylon 巴比伦塔(DAG上的动态规划)
来源:互联网 发布:淘宝店铺首页分析报告 编辑:程序博客网 时间:2024/05/17 07:31
题意:给n中立方体,每种无限多个,求能堆成塔的最高高度(必须严格满足上面的长宽小于下面的)
AC代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=30+2;struct node{int x,y,z;node(int x=0,int y=0,int z=0):x(x),y(y),z(z){}bool operator<(const node& n)const {return x<n.x&&y<n.y || x<n.y&&y<n.x;}}nt[maxn*3];int g[maxn*3][maxn*3];int d[maxn*3];int n;int dp(int i,int h){int& ans=d[i];if(ans>0)return ans;ans=h;for(int j=0;j<n*3;j++)if(g[i][j])ans=max(ans,dp(j,nt[j].z)+h);return ans;}int main(){int count1=0;while(scanf("%d",&n)==1 && n){int c=0;for(int i=0;i<n;i++){int x,y,z;scanf("%d%d%d",&x,&y,&z);nt[c++]=node(x,y,z); //第三位表示高度 nt[c++]=node(x,z,y);nt[c++]=node(y,z,x);}memset(d,0,sizeof(d));memset(g,0,sizeof(g));for(int i=0;i<n*3;i++) for(int j=0;j<n*3;j++) if(nt[i]<nt[j])g[i][j]=1; int ans=-1e5; for(int i=0;i<n*3;i++) ans=max(ans,dp(i,nt[i].z));printf("Case %d: maximum height = %d\n",++count1,ans);}return 0;}
1 0
- UVA 437 The Tower of Babylon 巴比伦塔(DAG上的动态规划)
- The Tower of Babylon DAG上的动态规划+uva
- UVA 437 The Tower of Babylon(DAG上的动态规划)
- UVa 437 - The Tower of Babylon(DAG动态规划)
- 动态规划 DAG问题uva 437 The Tower of Babylon
- uva 437 The Tower of Babylon(DAG的DP)
- uva 437 The Tower of Babylon 巴比伦塔
- UVA 437 The Tower of Babylon (DAG上的无源最长路 or LIS)
- UVA 437 巴比伦塔(DAG上的动态规划)
- uva 437 The Tower of Babylon(DAG最长路)
- UVA 437 - The Tower of Babylon (DAG)
- uva 437 The Tower of Babylon (DAG)
- UVA 437The Tower of Babylon (DAG)
- UVa 437 巴比伦塔(The Tower of Babylon)详细题解
- UVa-437 例题9-2 巴比伦塔(The Tower of Babylon)
- 例题9-2 巴比伦塔(The Tower of Babylon, UVa 437)
- uva437 - The Tower of Babylon(DAG上的DP)
- UVa 437 The Tower of Babylon(动态规划)
- Java Reference概念整理
- Remove Element针对删除元素多和少的两种情况解析
- URI和URL有什么区别
- 框架搭建之BaseActivity
- 【HPUOJ】Divide the pears (poj1664)
- UVA 437 The Tower of Babylon 巴比伦塔(DAG上的动态规划)
- Vue.js学习系列(五)---vuejs指令
- LeetCode 92. Reverse Linked List II
- WordPress分类页面获取当前分类的ID
- 自然语言查询接口IDCQ(二)算法描述
- 内存
- ROS gazebo激光传感器扫描存在部分扫描没有值问题
- HDU2102-A计划
- get_the_category_list