题目链接: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)的更多相关文章

  1. hdu-1069(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:一群猴子,给出n块砖的长x宽y高z,用这些砖拼起的高度最高是多少, 要求底下的砖的长宽都要 ...

  2. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  3. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  4. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  5. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  6. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  7. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  8. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

  9. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

随机推荐

  1. string的不可变性

    1.不可变性 代码如下: static void Main(string[] args){string str1 = "a";string str2 = str1;str2 = & ...

  2. <转载>网页设计中的F式布局

    地址:http://www.uisdc.com/understanding-the-f-layout-in-web-design 网页设计中的F式布局 今天我们来重点介绍网页设计中的F式布局.传统的布 ...

  3. GreenDAO数据库版本升级

    GreenDAO是一款非要流行的android平台上的数据库框架,性能优秀,代码简洁. 初始化数据库模型代码的时候需要使用java项目生成代码,依赖的jar包已经上传到我的资源里了,下载地址如下:ht ...

  4. 14.10.4 Defragmenting a Table 整理表

    14.10.4 Defragmenting a Table 整理表: 随机插入或者删除从一个secondary index 可以导致index变的fragmented Fragmentation意味着 ...

  5. 基于visual Studio2013解决C语言竞赛题之1074八皇后

        题目 解决代码及点评 /************************************************************************/ /* ...

  6. 能够返回运行结果的system函数加强版本号

    /*********************************************************************  * Author  : Samson  * Date   ...

  7. Entity FramWork - 在VS里面直接创建表,并同步到数据库

    前面具体添加什么直接看: 1.Entity - 使用EF框架进行增删改查 - 模型先行 2.Entity - 使用EF框架进行增删改查 - 数据库先行 然后: 然后右键,可以添加[实体],也就是表.之 ...

  8. UML之九图概述

    最近看了UML的九种图的讲解,这九种图在我们以后的学习中起着举足轻重的作用,不管是在写文档,还是在对系统的需求.设计进行分析时,都很重要,所以首先做一下概述,希望能和大家分享. 首先和大家展示一下我对 ...

  9. 双向DFS模板题

    B. Book of Evil time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  10. 做SEO推广必须要做的9件事儿

    SEO推广是由网站优化网络运营媒体宣传结合的一种技术,而现在恰好就是媒体最为流行,真因为如此很多的站长之知道利用自媒体推广网站,结果推广了几年网站权重只有2到3而已,导致和谐问题的关键就是没有结合其他 ...