UVa 437 - The Tower of Babylon(DP)
来源:互联网 发布:淘宝网秋季女装新款 编辑:程序博客网 时间:2024/05/17 05:05
给出n种长方体, 每种可以取多个, 每个长方体只能放在顶面长宽严格小于它的长方体上, 求出最高能放多高。
一道DAG。
设出dp[id][k], 表示第id个长方体第k条边做高时的状态。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxv = 30 + 5;struct Cub { int d[maxv];};int n, d[maxv][maxv];Cub cub[maxv];int dp(int id, int k) { if(d[id][k]) return d[id][k]; int t = 0; d[id][k] = cub[id].d[k]; for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { if((cub[i].d[(j + 1) % 3] < cub[id].d[(k + 1) % 3] && cub[i].d[(j + 2) % 3] < cub[id].d[(k + 2) % 3]) || (cub[i].d[(j + 1) % 3] < cub[id].d[(k + 2) % 3] && cub[i].d[(j + 2) % 3] < cub[id].d[(k + 1) % 3])) {// d[id][k] = max(d[id][k], d[id][k] + dp(i, j)); t = max(t, dp(i, j)); } } } return d[id][k] += t;}int main() {#ifndef ONLINE_JUDGE freopen("test", "r", stdin);#endif // ONLINE_JUDGE int Case = 0; while(cin >> n && n) { memset(d, 0, sizeof(d)); memset(cub, 0, sizeof(cub)); for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) cin >> cub[i].d[j]; sort(cub[i].d, cub[i].d + 3); } int res = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { dp(i, j); } } for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { res = max(res, d[i][j]); } } cout << "Case " << ++Case << ": maximum height = " << res << endl; } return 0;}
0 0
- Uva-437 The Tower of Babylon DP
- UVA 437 The Tower of Babylon | dp
- uva--437The Tower of Babylon+dp
- UVA 437 The Tower of Babylon DP
- DP--UVA - 437 The Tower of Babylon
- UVa--437 The Tower of Babylon(dp)
- UVA 437 The Tower of Babylon 【dp】
- uva 437 The Tower of Babylon(DAG的DP)
- uva 437 - The Tower of Babylon(DP)
- Uva 437-The Tower of Babylon(DP)
- UVA 437-The Tower of Babylon(DP)
- UVa 437 - The Tower of Babylon(DP)
- UVA 437The Tower of Babylon (dp + DAG最长序列)
- UVa 437 The Tower of Babylon (DP&DAG)
- uva 437 The Tower of Babylon(dp,记忆化搜索)
- UVA 437 The Tower of Babylon DP+记忆化
- UVA 437 (POJ 2241) The Tower of Babylon(DP)
- uva 437 The Tower of Babylon (DAG_变形 ,dp)
- md5 , sha-1简例
- 第五周项目 4 成员函数、友元函数和一般函数有区别(1)
- python中的函数any()和all()
- 欢迎使用CSDN-markdown编辑器
- tmux vim linux下的工作流
- UVa 437 - The Tower of Babylon(DP)
- 为VS2013安装VS2008(V90)的platform toolset
- android 调用系统拍照
- AutoCAD的AccoreConsole - 第二篇(执行脚本)
- float与double
- C#程序以管理员权限运行
- Leetcode-12 int to Roman
- Python-基础知识
- 应用springMVC时 JS等文件找不到错误