hdu1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
分析: 每种石头有六种方法,那么等效为:有6*n种石头。
根据x和y排序(要保证相应的x、y总有x>=y),然后dp[i]=
max{s[i].z,s[i].z+dp[j]}(j<i,且石块i放于石块j上,符合题意)。
其实就是最长上升子序列的换种求法。。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
using namespace std;
int dp[];
struct node
{
int x,y,z;
}s[];
int cmp(node a,node b)
{
if(a.x!=b.x)return a.x>b.x;
else if(a.y!=b.y)return a.y>b.y;
else return a.z>b.z;
}
int main()
{
int n,cas=;
while(scanf("%d",&n)&&n)
{
int tot=;
for(int i=;i<=n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
s[tot].x=x;s[tot].y=y;s[tot].z=z;
tot++;
s[tot].x=x;s[tot].y=z;s[tot].z=y;
tot++;
s[tot].x=y;s[tot].y=x;s[tot].z=z;
tot++;
s[tot].x=y;s[tot].y=z;s[tot].z=x;
tot++;
s[tot].x=z;s[tot].y=y;s[tot].z=x;
tot++;
s[tot].x=z;s[tot].y=x;s[tot].z=y;
tot++;
}
sort(s+,s+tot,cmp);
memset(dp,,sizeof(dp));
dp[]=s[].z;
int ans=-;
for(int i=;i<tot;i++)
{//printf("%d %d %d\n",s[i].x,s[i].y,s[i].z);
int mx=;
for(int j=;j<i;j++)
if(s[j].x>s[i].x&&s[j].y>s[i].y&&dp[j]+s[i].z>mx)mx=dp[j]+s[i].z;
if(mx==)dp[i]=s[i].z;
else
dp[i]=mx;
ans=max(mx,ans);
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
}
hdu1069(dp)的更多相关文章
- hdu-1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:一群猴子,给出n块砖的长x宽y高z,用这些砖拼起的高度最高是多少, 要求底下的砖的长宽都要 ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
随机推荐
- memset,memcpy,memmove,strcpy,strcat,strcmp的实现(其实很简单,每个程序都只有几行代码)
面试中的几个小问题 1.对stl中list封装(参考1): 2.对重要C函数实现(参考2): //memset void *memset(void *buffer, int c, int count) ...
- Qt4_VS10 程序打包发布
源地址:http://www.2cto.com/kf/201306/217205.html 目录结构如下: ---------------------------------------------- ...
- 《火球——UML大战需求分析》(第2章 耗尽脑汁的需求分析工作)——2.1 需求分析面面观
说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...
- 你以为在用SharePoint但事实上不是
博客地址 http://blog.csdn.net/foxdave 原文链接:http://www.techrepublic.com/blog/tech-decision-maker/you-thin ...
- android 使用Scroller实现缓慢移动
在Launcher中的Workspace中实现了左右屏幕切换效果,里面就用到了Scroller记录滑动轨迹,实现一种缓慢地向左或向右移动的效果,这里我对这种效果进行总结: 我们先看一个例子:点击按钮时 ...
- ABAP 向上取整和向下取整 CEIL & FLOOR
下面是一段关于CEIL 和 FLOOR 的代码 DATA:a TYPE mseg-menge, b TYPE mseg-menge, c TYPE mseg-menge. a = '1.36'. b ...
- IOS 可靠性测试 iosMonkey
UI AutoMonkey UI AUtoMonkey是一款非常简单的IOS压力测试工具.通过它,你可以向ios设备发送滑动.拖动.旋转.甚至锁屏和解锁指令.原文github地址:https://gi ...
- Delphi一共封装(超类化)了8种Windows基础控件和17种复杂控件
超类化源码: procedure TWinControl.CreateSubClass(var Params: TCreateParams; ControlClassName: PChar); con ...
- Window7下安装openssl完整版(亲测实现)
安装环境: 操作系统:window7(64位) C++编译器:VS2010 -------------------------------------------------------------- ...
- spring mvc3中的addFlashAttribute方法
spring mvc3中的addFlashAttribute方法