HDU 1069 Monkey and Banana (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
简单记录一下
思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可
转移方程 dp[i]=max(dp[i],dp[t]+a[i].z) //dp里存的是高度,a[i].z是第i个的高度
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
#define inf 0x3f3f3f3f
using namespace std;
struct node {
int x,y,z;
}a[];
bool cmp (node x, node y)
{
if (x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
int dp[];
int main ()
{
int n,m,i,t,sum,j=,k;
while(cin>>n)
{
j++;
if(n==)
break;
k=;
for(i=;i<n;++i)
{
int x,y,z;
cin>>x>>y>>z;
if(x==y==z)
a[k].x=x, a[k].y=y, a[k++].z=z;
else if (x==y)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=z, a[k].y=x, a[k++].z=y;
else if (x==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z;
else if (y==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=y, a[k].y=x, a[k++].z=z;
else
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z,
a[k].x=y, a[k].y=z, a[k++].z=x,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=z, a[k].y=x, a[k++].z=y;
}
sort(a,a+k,cmp);
for(i=;i<k;++i)
dp[i]=a[i].z;
int maxs=;
for(i=;i<k;++i)
for(t=;t<i;++t)
{
if(a[i].x>a[t].x &&a[i].y>a[t].y){
dp[i]=max(dp[i],dp[t]+a[i].z);
maxs=max(maxs,dp[i]);
}
}
cout<<"Case "<<j<<": maximum height = "<<maxs<<endl;
} return ;
}
HDU 1069 Monkey and Banana (动态规划)的更多相关文章
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- POJ 3525 /// 半平面交 模板
题目大意: 给定n,接下来n行逆时针给定小岛的n个顶点 输出岛内离海最远的点与海的距离 半平面交模板题 将整个小岛视为由许多半平面围成 那么以相同的比例缩小这些半平面 一直到缩小到一个点时 那个点就是 ...
- POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积
题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...
- cms系统视频分享
cms_001-CMS系统功能需求简介-1.avicms_002-如何采用用例分析方法来理解需求-1.avicms_003-后台管理系统用例-1.avicms_004-实现验证码的初步思路-1.avi ...
- 挂载U盘
.fdisk -l 查看当前系统存储盘 (sdaX一般是系统自带, sdbX则是外接) .mount /dev/sdbX /mnt/usb/ (如果usb目录不存在可创建新目录) .umount /m ...
- Windows 设置内网和外网同时使用
想要电脑同时使用内网和外网必须具备两个网卡,一个是无线网卡一个是本地连接,无线网卡用来连接wifi也就是外网,而本地连接需要网线连接内网,外网是不需要做设置的,我们只需要设置内网即可,鼠标右击电脑右下 ...
- 单调栈——cf777E
傻逼单调栈啊我怎么想了半天dp #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef st ...
- CF459E Pashmak and Graph (Dag dp)
传送门 解题思路 \(dag\)上\(dp\),首先要按照边权排序,然后图都不用建直接\(dp\)就行了.注意边权相等的要一起处理,具体来讲就是要开一个辅助数组\(g[i]\),来避免同层转移. 代码 ...
- flutter中的BuildContext
https://www.jianshu.com/p/509b77b26b78
- C# GZipStream 压缩 解压
关于GZipStream压缩解压,网上找了很多资料,完整的不多,要么是针对字符串压缩解压缩的,要么只实现了针对单个文件的压缩解压缩,还有的不支持子文件夹的压缩,实用性都不是很大. 以下整理了压缩解压缩 ...
- 委托_deleget
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...