http://acm.hdu.edu.cn/showproblem.php?pid=1069

意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定。

你可以选任意两个参数作为长和宽,第三个是高。

然后要求把箱子搭起来,使得高度最高。

能搭的前提是下面那个箱子的长和宽都 > 上面那个箱子的。

思路:

因为同一个箱子可以产生6中不同的箱子,而每种最多选一个,因为相同的箱子最多只能搭起来一个。

那么可以把所有箱子都弄出来,排序,就是LIS的题目了。

dp[i]表示以i这个箱子为结尾的最大高度。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int n;
struct node {
int L, W, H;
node(int LL, int WW, int HH) : L(LL), W(WW), H(HH) {}
node() {}
bool operator < (const struct node & rhs) const {
if (L != rhs.L) return L > rhs.L;
else if (W != rhs.W) return W > rhs.W;
else return H > rhs.H;
}
}a[maxn];
int dp[maxn];
bool isok(int one, int two) {
if (a[one].L > a[two].L && a[one].W > a[two].W) return true;
else return false;
}
void work () {
int t = ;
for (int i = ; i <= n; ++i) {
int x, y, z;
cin >> x >> y >> z;
a[++t] = node(x, y, z);
a[++t] = node(x, z, y);
a[++t] = node(y, x, z);
a[++t] = node(y, z, x);
a[++t] = node(z, x, y);
a[++t] = node(z, y, x);
}
sort(a + , a + + t);
for (int i = ; i <= t; ++i) {
dp[i] = a[i].H;
for (int j = ; j < i; ++j) {
if (isok(j, i)) {
dp[i] = max(dp[i], dp[j] + a[i].H);
}
}
}
int ans = -inf;
for (int i = ; i <= t; ++i) {
ans = max(ans, dp[i]);
}
static int f = ;
printf("Case %d: maximum height = %d\n", ++f, ans);
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
// IOS;
while (cin >> n && n) work();
return ;
}

最新文章

  1. 理解C# 4 dynamic(1) - var, object, dynamic的区别以及dynamic的使用
  2. eclipse安装genymotion插件。
  3. NHibernate 映射失败 is not mapped
  4. 内存映射文件mmap
  5. JS获取用户控件中的子控件Id
  6. squid代理服务器搭建及配置
  7. Java显式锁学习总结之二:使用AbstractQueuedSynchronizer构建同步组件
  8. [LCA模版] Distance Queries
  9. postgres 基本操作
  10. 纯CSS制作图形效果
  11. 描述: http通讯基础类
  12. Linux系统Oracle启动、关闭
  13. eclipse git 分享项目到GitHub上
  14. WEB框架Django之ORM操作
  15. Egret(白鹭引擎)——Egret+fairyGui 实战项目入门
  16. 中南大学oj:1352: New Sorting Algorithm
  17. yii---生产链接的方法
  18. JQ 确定与取消弹出框,选择确定执行Ajax
  19. pycharm中的常用快捷键
  20. 比较两个JSON字符串是否完全相等

热门文章

  1. listen 76
  2. 华为机试 可怕的N阶乘
  3. 3170: [Tjoi 2013]松鼠聚会
  4. C++之迭代器失效总结
  5. Jenkins持续集成环境搭建
  6. AI-Info-Micron-Insight:在线购物算法的核心是强大的 DRAM
  7. 用位运算实现四则运算之加减乘除(用位运算求一个数的1/3) via Hackbuteer1
  8. DataWindow.Net V2.5原始文件下载
  9. Entity Framework之领域驱动设计实践
  10. SQL 调用 webservice