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

  1. 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 ...

  2. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  3. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  4. HDU 1069 Monkey and Banana(动态规划)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  5. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. hdu 1069 Monkey and Banana

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

随机推荐

  1. 织梦自增函数[field:global name=autoindex/]常见用法

    看来不少朋友需要不了解这个自增函数的用法,在这里我列举一些常见的写法以及作用.   [field:global name=autoindex/] !--普通打印递增的数字-- [field:globa ...

  2. Error creating bean with name 'unMblTotController': 注入失败

    今天新来的小伙子,进公司做项目,然后自己新建了包,出了以下错误 y.UnsatisfiedDependencyException: Error creating bean with name 'unM ...

  3. oracle中的decode函数的使用

    含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译值1)ELSIF 条件=值2 THEN R ...

  4. 再次封装ajax函数,统一入口

    根据API写网页的时候,每个页面都需要ajax请求,每次都写一大堆请求,配置什么的太麻烦,于是打算封装一个ajax函数,统一调用: 开始时是使用return返回ajax,如下: function cr ...

  5. C 常见字符串操作函数

    头文件 <string.h> 1. char *strstr(const char *str1, const char *str2);      判断str2是否为str1的子串  //s ...

  6. vue组件参数校验

    代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...

  7. css---盒模型新增样式

    box-shadow 以逗号分割列表来描述一个或多个阴影效果,可以用到几乎任何元素上. 如果元素同时设置了 border-radius ,阴影也会有圆角效果.多个阴影时和多个 text shadows ...

  8. 宝塔面板安装swoole扩展

    Swoole是一个PHP扩展,扩展不是为了提升网站的性能,是为了提升网站的开发效率.最少的性能损耗,换取最大的开发效率.利用Swoole扩展,开发一个复杂的Web功能,可以在很短的时间内完成 Swoo ...

  9. 0917CSP-S模拟测试赛后总结

    机房搬家后的首战,便是失利. 依旧是挂掉了.这次状态有大问题. 然而状态的问题归根结底还是实力不行. 大约一个小时左右我拿到了T1的部分分.赛时判断了一下大概是高分. (不过赛后发现确实不算什么太高的 ...

  10. (JS)应为","

    在写cshtml的时候,vs提示:(JS)应为"," 功能无法实现,一般是因为 标点切成全角了,但是我是应为把‘’打成了“” 以下错误示范: $("ol").a ...