动态规划,最大上升子序列和。不同的是给的是长方体。

为了方便处理,笔者直接将每个长方体当做三个长方体处理,每个长方体的长大于等于宽。然后以长为主,宽为辅排序。

然后就和之前的那道FatMouse‘s speed一样了,当符合条件是,更新最大值。

下面是笔者第一次AC的代码:

#include <iostream>
#include <algorithm>
using namespace std;struct State
{int length;int width;int height;int sum;
} s[100];int cmp(const State& a,const State& b)
{if(a.length!=b.length)return (a.length<b.length);elsereturn (a.width<b.width);
}int main()
{int i,j,n,max,cas=1,a,b,c;while(cin>>n && n){for(i=0;i<n;i++){cin>>a>>b>>c;if(a==b && b==c)s[i].height=s[i].length=s[i].width=s[i].sum=a;else{s[i+2].length=s[i+1].height=s[i].length=a>b?(a>c?a:c):(b>c?b:c);s[i+2].width=s[i+1].width=s[i].height=a<b?(a<c?a:c):(b<c?b:c);s[i+2].height=s[i+1].length=s[i].width=a+b+c-s[i].length-s[i].height;i+=2;n+=2;}}sort(s,s+n,cmp);max=s[0].sum=s[0].height;for(i=1;i<n;i++){s[i].sum=s[i].height;for(j=0;j<i;j++){if(s[i].length>s[j].length && s[i].width>s[j].width && s[i].sum<s[j].sum+s[i].height){s[i].sum=s[j].sum+s[i].height;if(max<s[i].sum)max=s[i].sum;}}}cout<<"Case "<<cas++<<": maximum height = "<<max<<endl;}
}

然后,笔者又把代码精简了一点点(笔者非常喜欢短一点。。。测试AC了):

#include <iostream>
#include <algorithm>
using namespace std;struct State
{int length;int width;int height;int sum;
} s[100];int cmp(const State& a,const State& b)
{if(a.length!=b.length)return (a.length<b.length);elsereturn (a.width<b.width);
}int main()
{int i,j,n,max,cas=1,a,b,c;while(cin>>n && n){for(i=0;i<n;i++){cin>>a>>b>>c;if(a==b && b==c)s[i].height=s[i].length=s[i].width=s[i].sum=a;else{s[i+2].length=s[i+1].sum=s[i+1].height=s[i].length=a>b?(a>c?a:c):(b>c?b:c);s[i+2].width=s[i+1].width=s[i].sum=s[i].height=a<b?(a<c?a:c):(b<c?b:c);s[i+2].sum=s[i+2].height=s[i+1].length=s[i].width=a+b+c-s[i].length-s[i].height;i+=2;n+=2;}}sort(s,s+n,cmp);max=s[0].sum=s[0].height;for(i=1;i<n;i++)for(j=0;j<i;j++)if(s[i].sum<s[j].sum+s[i].height && s[i].length>s[j].length && s[i].width>s[j].width)if(max<(s[i].sum=s[j].sum+s[i].height))max=s[i].sum;cout<<"Case "<<cas++<<": maximum height = "<<max<<endl;}
}

转载于:https://www.cnblogs.com/IT-BOY/archive/2013/02/04/2892326.html

HDOJ 1069 Monkey and Banana 解题报告相关推荐

  1. HDOJ 1069 Monkey and Banana

    1:每一组X,Y,Z对应3个立方体 2:按面积从小到大DP Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  2. HDUOJ 1069 Monkey and Banana

    HDUOJ 1069 Monkey and Banana 题目链接 Problem Description A group of researchers are designing an experi ...

  3. HDU 1069 Monkey and Banana 最长上升子序列进阶(动态规划)

    HDU 1069(动态规划) Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  4. HDU 1069 Monkey and Banana(简单图解,经典DP,最大上升子序列变形)

    题目链接 今天做的第二题,感觉比较经典,详细记录一下吧! Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  5. 杭电1069 Monkey and Banana

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1069 一开始看到这题我想不到什么思路,后来翻<算法竞赛入门经典>时发现它是第九章第二节的例 ...

  6. 三维最长上升子序列问题——HDU 1069 Monkey and Banana

    题目: A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a ...

  7. hdu 1069 Monkey and Banana (LIS)

    Problem - 1069 随便找到的一道题目. 题意是给出一些的长方体,长方体可以用任意次数,可以任意翻转.如果一个长方体可以叠在另一个长方体上,条件是这个长方体的长和宽严格小于另一个长方体的长和 ...

  8. hdu(1069)——Monkey and Banana(LIS变形)

    题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...

  9. HDOJ 1754 I Hate It 解题报告

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

最新文章

  1. 侠客风云传服务器维护,《侠客风云传online》4月20日服务器数据互通公告
  2. Java黑皮书课后题第5章:*5.15(显示ASCII码字符表)编写一个程序,打印ASCII字符表从‘!‘到‘~‘的字符。每行打印10个字符。ASCII码表如附录B所示。数字之间用一个空格字符隔开
  3. 23天的单车旅行,从广州到四川,篇首语
  4. 方法参数名称和Spring
  5. www.python123.org_python爬虫-requests
  6. 95-190-442-源码-window-Trigger-ProcessingTimeTrigger
  7. 牛客网 牛客小白月赛1 C.分元宵-快速幂
  8. php正则匹配sg-nc-wap_PHP正则表达式匹配关键字之外HTML标签a
  9. 如何判断浏览器/标签是否有效[重复]
  10. 4.企业安全建设入门(基于开源软件打造企业网络安全) --- 威胁情报
  11. java文件读取的几个操作-1
  12. MATLAB:绘制用户给定的01序列图并计算其对应的AMI编码,双相编码和CMI编码
  13. linux 实时显示网速,linux 实时显示网速bash
  14. 利用地图API定制开发电子地图应用系统
  15. win7命令设置自动关机
  16. java专有技术名词_关于Java的专有名词
  17. Linux互斥锁详细解读,看这一篇就够了
  18. Git分支的作用与使用
  19. HuaWei(手机)瘦身
  20. 顺序表 - 地址计算

热门文章

  1. 中专生女生学高铁还是计算机,女生学习高铁乘务专业好就业吗
  2. java模拟登录百度_模拟登陆百度的Java实现
  3. 2023年PMP考试,报名指导+新考纲资料,一文get
  4. nginx配置vhost例子
  5. 斗地主游戏Landlord
  6. 基于Java毕业设计校园一卡通服务平台源码+系统+mysql+lw文档+部署软件
  7. Shortest Path
  8. 怎么搭建一个C语言的开发环境?
  9. 微信小程序轮播中的current_微信小程序轮播图
  10. 2021-10-19-PDFJS使用基础教程