HDU 1069 DP
来源:互联网 发布:mac os x mavericks 编辑:程序博客网 时间:2024/06/05 16:17
题解:首先我们要发现,这个题每一种长方体其实最多也就使用一次,因为题目说下面的要严格大于上面的低和宽,这样的话我们就可以把一个长方体拆成三个,分别作低和宽,然后我们按照底面的大小之类的东西排个序 (注意这个地方必须排序,因为这里不同于背包,选了前面对后面没有影响这个题目是有影响的)所有两个的话你会怎么选 非常关键 然后就是dp了
dp(i) 表示前 i 个并且选择第 i 个的最大高度dp(i) = dp (j) + high (i); 其中 j < i 并且i 能放在 j 上面
#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;const int maxn = 305;struct node { int len,wid; int high;}arr[maxn];int dp[maxn] = {0};int cnt = 0;void build (int a,int b,int c) { if (a < b) swap (a,b); arr[cnt].len = a,arr[cnt].wid = b,arr[cnt].high = c; cnt ++;}bool cmp (const node a,const node b) { if (a.len == b.len) return a.wid > b.wid; return a.len > b.len;}int main () { ios_base :: sync_with_stdio(false); int n; int cas = 1; while (cin >> n && n) { cnt = 0; for (int i = 1;i <= n; ++ i) { int a,b,c; cin >> a >> b >> c; build(a, b, c); build(a, c, b); build(b, c, a); } sort (arr,arr + cnt,cmp); memset (dp,0,sizeof(0)); dp[0] = 0; int ans = 0; for (int i = 0;i < cnt; ++ i) { dp[i] = arr[i].high; ans = max (ans,dp[i]); for (int j = 0;j < i; ++ j) { if (arr[j].len > arr[i].len && arr[j].wid > arr[i].wid) { dp[i] = max (dp[i],dp[j] + arr[i].high); ans = max (dp[i],ans); } } } cout << "Case "<< cas++ <<": maximum height = "; cout << ans << endl; } return 0;}
阅读全文
0 0
- HDU 1069 dp
- HDU 1069 DP
- hdu 1069 DP
- HDU 1069 DP
- hdu 1069 dp
- HDU 1069 dp
- hdu 1069 dp
- HDU 1069 (DP)
- HDU 1069 DP 经典
- hdu 1069 (dp)
- DP HDU-1069
- #HDU 1069 简单dp
- HDU 1069 dp??
- hdu 1069(dp)
- HDU 1069 DP
- hdu 1069 dp
- [DP] HDU 1069
- HDU DP
- Linux文件系统目录结构详解
- DES算法
- leetcode 381. Insert Delete GetRandom O(1)
- 模拟量信号干扰分析及解决方案
- 设计模式笔记3-装饰模式
- HDU 1069 DP
- Mybatis之动态 SQL
- 大电容滤低频,小电容滤高频?——滤波电容的选择
- 深入分析Cookie的安全性问题
- linux下搭建属于自己的博客(WordPress安装)
- Skynet SourceCode browse Centos VSCode Config Tutorial
- PAT-A1132
- spring boot集成Dozer转换器
- Golang