UVA 437 The Tower of Babylon(LIS型DP~水)
来源:互联网 发布:linux 重启网络服务 编辑:程序博客网 时间:2024/06/15 21:32
看经典入门里面有这个例题,便找来做了,刚开岁还是一脸懵逼,看了别人解答,说是最长上升公共子序的类型,后来发现果然是,不难不难!
要好好啃入门经典的DP部分了
#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;struct Block{ int l, w, h;} B[303];bool cmp(const Block &X, const Block &Y){ if (X.l == Y.l) return X.w < Y.w; return X.l < Y.l;}int LIS[303];int main(void){ int N, l, w, h; int t = 1; while (scanf("%d", &N) && N) { int index = 0; memset(LIS, 0, sizeof(LIS)); memset(B, 0, sizeof(B)); for (int i = 0; i < N; i++) { scanf("%d%d%d", &l, &w, &h); B[index++] = {l, w, h}; B[index++] = {l, h, w}; B[index++] = {w, l, h}; B[index++] = {w, h, l}; B[index++] = {h, w, l}; B[index++] = {h, l, w}; } sort(B, B + index, cmp); int MAX = 0; for (int i = 0; i < index; i++) { LIS[i] = B[i].h; for (int j = 0; j < i; j++) { if (B[j].l < B[i].l && B[j].w < B[i].w && LIS[j] + B[i].h > LIS[i]) { LIS[i] = LIS[j] + B[i].h; } } if (LIS[i] > MAX) MAX = LIS[i]; } printf("Case %d: maximum height = %d\n", t++, MAX); } return 0;}
阅读全文
0 0
- UVA 437 The Tower of Babylon(LIS型DP~水)
- UVa 437 - The Tower of Babylon LIS
- 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 437The Tower of Babylon (dp + DAG最长序列)
- uva 437 - The Tower of Babylon(DP)
- 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(DP)
- UVA 437-The Tower of Babylon(DP)
- EGLDisplay
- MySql 数据库获取汉字首字母
- 学习PHP函数记录
- Spring Security 基本套路
- LeetCode 9.Palindrome Numbe
- UVA 437 The Tower of Babylon(LIS型DP~水)
- 使用Markdown来编写博客
- Lucene6入门教程(七)多目录多线程索引/检索
- uva 10491 概率
- android中多线进程开发
- 有关JS构造函数
- pioneer3AT/DX沿墙壁行走并记录数据
- 学习PHP所有知识点
- shell脚本 冒泡法对数字排序