【动态规划】[UVA 437]The Tower of Babylon
来源:互联网 发布:身份证识别软件原理 编辑:程序博客网 时间:2024/05/20 19:33
令
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 1000;int f[MAXN+10][3];int d[MAXN+10][3];bool check(int i, int h1, int j, int h2){ int a1=d[i][0], b1=d[i][1], a2=d[j][0], b2=d[j][1]; if(h1 != 2){ if(h1 == 1) b1 = d[i][2]; else a1 = d[i][2]; } if(h2 != 2){ if(h2 == 1) b2 = d[j][2]; else a2 = d[j][2]; } if(a1 > b1) swap(a1, b1); if(a2 > b2) swap(a2, b2); if(a1 < a2 && b1 < b2) return true; return false;}int rans, n;int dp(int u, int m){ int &ans = f[u][m]; if(ans > 0) return ans; for(int i=1;i<=n;i++){ for(int v=0;v<3;v++) if(check(i, v, u, m)) ans = max(ans, dp(i, v)); } ans += d[u][m]; return rans=max(rans,ans), ans;}int main(){ int ccnt = 0; while(scanf("%d", &n)!=EOF && n!=0){ memset(f, 0, sizeof f); rans = 0; for(int i=1;i<=n;i++) scanf("%d%d%d", &d[i][0], &d[i][1], &d[i][2]); for(int i=1;i<=n;i++) for(int v=0;v<3;v++) dp(i, v); printf("Case %d: maximum height = %d\n", ++ccnt, rans);} return 0;}
0 0
- 动态规划 DAG问题uva 437 The Tower of Babylon
- UVa 437 The Tower of Babylon(动态规划)
- UVa 437 - The Tower of Babylon(DAG动态规划)
- 【动态规划】[UVA 437]The Tower of Babylon
- uva 动态规划 437 The Tower of Babylon
- 【动态规划】UVa 437 The Tower of Babylon
- UVA 437 The Tower of Babylon (动态规划)
- The Tower of Babylon DAG上的动态规划+uva
- UVA437 The Tower of Babylon 动态规划
- [动态规划]UVA437 - The Tower of Babylon
- UVA437 - The Tower of Babylon - 动态规划
- uva 437 The Tower of Babylon(动态规划 嵌套矩形问题最长路)
- UVA 437 The Tower of Babylon(DAG上的动态规划)
- UVA 437 The Tower of Babylon 巴比伦塔(DAG上的动态规划)
- 437 - The Tower of Babylon(动态规划)
- uva 437 The Tower of Babylon
- UVa 437 - The Tower of Babylon
- UVA 437 The Tower of Babylon
- 新项目开发环境搭建遇到的问题排查(cannot assign requested address)
- Thinking in Java--Java多线程学习笔记(1)
- JAVA学习方法分享
- 命令查看APK文件的信息
- 关于sql连接语句中的Integrated Security=SSPI
- 【动态规划】[UVA 437]The Tower of Babylon
- Nginx+uwsgi+Django部署实战
- Hadoop中MapReduce多种join实现实例分析
- ubunt下安装sqlite3
- android UI 设计
- Ubuntu使用相关问题汇总
- Android 自定义 ViewPager 打造千变万化的图片切换效果
- php解决各种excel表格形式导出问题
- Android Studio系列教程一--下载与安装