kuangbin专题十二 HDU1069 Monkey and Banana
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069
题目大意:给出n种长方体的x,y,z(任意个),然后堆起来(要求严格小于自己下面的长方体),求能达到的最大高度。
经典的矩形嵌套:把每种长方体的6种方法都存储起来,然后排序,然后再像上升子序列dp一样。见注释
AC代码:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define forn(i, x, n) for(int i = (x); i < n; i++)
#define nfor(i, x, n) for(int i = n-1; i >= x; i--)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-5;
const ll mod = 1e9+7;struct node{int l, w, h;
}stu[200];
int dp[200];//dp[i] 表示 i能达到的最高高度 bool cmp(node a, node b) {//先x 后 y if(a.l == b.l)return a.w < b.w;return a.l < b.l;
}int main() {int n, x, y, z, cur;int icase = 1;while(~scanf("%d", &n),n) {cur = 0;while(n--) {scanf("%d%d%d", &x, &y, &z);//存储6种状态 stu[cur].l = x; stu[cur].w = y; stu[cur++].h = z; stu[cur].l = x; stu[cur].w = z; stu[cur++].h = y;stu[cur].l = y; stu[cur].w = z; stu[cur++].h = x;stu[cur].l = y; stu[cur].w = x; stu[cur++].h = z;stu[cur].l = z; stu[cur].w = x; stu[cur++].h = y;stu[cur].l = z; stu[cur].w = y; stu[cur++].h = x;}sort(stu, stu+cur, cmp);//排序 mem(dp, 0);int maxx = -inf;forn(i, 0, cur) {dp[i] = stu[i].h;//初始化 forn(j, 0, i) {//找到使自己最高的 if(stu[j].l < stu[i].l && stu[j].w < stu[i].w) {dp[i] = max(dp[j] + stu[i].h, dp[i]);}}maxx = max(maxx, dp[i]);//更新最高高度 }maxx = max(0, maxx);printf("Case %d: maximum height = %d\n", icase++, maxx);}
}
kuangbin专题十二 HDU1069 Monkey and Banana相关推荐
- kuangbin专题十二 基础DP
kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...
- kuangbin 专题十二: 基础DP1 Tickets
题目链接: 传送门 #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- [kuangbin带你飞]专题十二 基础DP1 C - Monkey and Banana HDU - 1069
C - Monkey and Banana HDU - 1069 题目链接:https://vjudge.net/contest/68966#problem/C 题目: A group of rese ...
- [kuangbin带你飞]专题十二 基础DP1 题解+总结
kuangbin带你飞:点击进入新世界 总结: 简单dp,最近在做,持续更新. 文章目录 总结: 1.Max Sum Plus Plus 2.Ignatius and the Princess IV ...
- [kuangbin带你飞]专题十二 基础DP1
A - Max Sum Plus Plus (HDU 1024) 题意:将n个数取m段且不相交,求m段数字和最大值: dp[i][j]:前i个数字分成j段的最大值. 边界dp[0][0] = 0; d ...
- [C#基础知识系列]专题十二:迭代器
引言: 在C# 1.0中我们经常使用foreach来遍历一个集合中的元素,然而一个类型要能够使用foreach关键字来对其进行遍历必须实现IEnumerable或IEnumerable<T> ...
- [C# 网络编程系列]专题十二:实现一个简单的FTP服务器
引言: 休息一个国庆节后好久没有更新文章了,主要是刚开始休息完心态还没有调整过来的, 现在差不多进入状态了, 所以继续和大家分享下网络编程的知识,在本专题中将和大家分享如何自己实现一个简单的FTP服务 ...
- 专题十二:实现一个简单的FTP服务器
引言: 在本专题中将和大家分享如何自己实现一个简单的FTP服务器.在我们平时的上网过程中,一般都是使用FTP的客户端来对商家提供的服务器进行访问(上传.下载文件),例如我们经常用到微软的SkyDriv ...
- kuangbin专题十六 KMP扩展KMP HDU3068 最长回文
给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input输入有多组case,不超过120组,每组输入为 ...
- kuangbin专题十六 KMP扩展KMP HDU2594 Simpsons’ Hidden Talents
Homer: Marge, I just figured out a way to discover some of the talents we weren't aware we had. Marg ...
最新文章
- 【SLAM建图和导航仿真实例】(三)- 使用RTAB-MAP进行SLAM建图和导航
- Python 进阶_OOP 面向对象编程_类属性和方法
- “习惯测试”三步法,打造完美用户体验
- 【Flutter】StatelessWidget 组件 ( Container 组件 | BoxDecoration 组件 | Text 组件 | Icon 组件 )
- LeetCode 121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock)
- 2017年9月2日普级组T2 跳格子
- DataTable某一列的值转化成集合
- 网易云信启动“T服务”,为开发加速
- javascript数组的各种操作
- oracle强制drop用户,强制Oracle Drop全局临时表
- python func函数用法_python教程:3个非常有用的内置函数
- 《企业软件交付:敏捷与高效管理精要》——2.8 结论
- 【SPOJ5971】LCMSUM
- 再解Java中的String
- PowerDesigner数据库设计PDM基于Excel的导入导出总结
- Lua调用c++ DLL 文件
- w ndows7错误恢复,windows7错误恢复进不去循环 从根本上解决问题
- CLIENT_PLUGIN_AUTH is required 解决办法
- 《百万IT毕业生的心声:IT专业大学生毕业前必做的十件事》
- ES集群安装错误记录