题意:

N(不超过30)种木块,每种木块有长、宽、高x,y,z。

木块A可以搭在木块B上当且仅当A的底面长和宽都分别小于B的顶面的长与宽,即不能有超出B的部分。

问垒起来的“木块塔”的最大高度。

思路:

每种木块有6种形态,所以总共有6*N种木块,列张二维关系表,然后记忆搜。

代码:

struct node{
int x,y,z;
}
b[355]; int dp[355];
int c;
bool mp[355][355]; int dfs(int x){
if(dp[x]!=-1) return dp[x];
bool yes = false;
rep(i,1,c) if(mp[x][i]){
dp[x] = max( dp[x],dfs(i)+b[x].z );
yes = true;
}
if(yes==false){
dp[x]=b[x].z;
}
return dp[x];
} int main(){ int n;
int T=0;
while(scanf("%d",&n)!=EOF && n>0){
rep(i,1,n){
scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].z);
}
c = n;
rep(i,1,n){
b[++c].x=b[i].y; b[c].y=b[i].x; b[c].z=b[i].z;
b[++c].x=b[i].x; b[c].y=b[i].z; b[c].z=b[i].y;
b[++c].x=b[i].z; b[c].y=b[i].y; b[c].z=b[i].x;
b[++c].x=b[i].z; b[c].y=b[i].x; b[c].z=b[i].y;
b[++c].x=b[i].y; b[c].y=b[i].z; b[c].z=b[i].x;
} mem(mp,false); //mp[i][j]==true:第i种可以放到第j种上 rep(i,1,c){
rep(j,1,c){
if(b[i].x<b[j].x && b[i].y<b[j].y){
mp[i][j]=true;
}
if(b[i].x>b[j].x && b[i].y>b[j].y){
mp[j][i]=true;
}
}
} mem(dp,-1);
int ans = -1; rep(i,1,c){
if(dp[i]==-1){
ans = max( ans,dfs(i) );
}else{
ans = max( ans,dp[i] );
}
} printf("Case %d: maximum height = %d\n",++T,ans);
} return 0;
}

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(二维偏序LIS的应用)

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

  5. HDU 1069 Monkey and Banana (DP)

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

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

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

  7. hdu 1069 Monkey and Banana

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

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

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

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

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

随机推荐

  1. url传参和解决中文乱码

    在A页面把参数传给B页面 index.html?name="张三" 在B页面接收(js) function getQueryString(name) { var result = ...

  2. 一个简单的session传值学习

    a.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  3. Docker入门系列之一:什么是Docker?

    原文作者:Jeff Hale 原文地址:https://towardsdatascience.com/learn-enough-docker-to-be-useful-b7ba70caeb4b 翻译: ...

  4. windows 中cmd一些特殊命令

    chcp 65001  就是换成UTF-8代码页 chcp 936 可以换回默认的GBK chcp 437 是美国英语 shutdown -s -t 60   60秒后关机 shutdown /a  ...

  5. C# 获取动态类中所有的字段

    /// <summary>        /// 动态类 获取字典集合        /// </summary>        /// <typeparam name= ...

  6. Writing in the Science 01

    INTRODUCTION What makes good writing? Good writing communicates an idea clearly and effectively. Goo ...

  7. shell 一些常用命令

    一般自己虚拟机新安装的centos才需要此配置 setenforce 是Linux的selinux防火墙配置命令 执行setenforce 0 表示关闭selinux防火墙. getenforce 查 ...

  8. 数据库管理软件navicate12的激活和安装

    前言   太多做测试或开发的小伙伴需要写sql语句,激活版navicat版本它来了 准备软件 navicat12安装包 navicat注册机 百度网盘下载链接(永久有效): 链接:https://pa ...

  9. Unittest 框架之断言,你学会了吗??

    unittest断言 Python在 unittest.TestCase 类中提供了很多断言方法.断言方法检查你认为应该满足的条件是否确实满足.如果该条件确实满足,你对程序行为的假设就得到了确认,你就 ...

  10. Python+requests环境搭建和GET基本用法

    Python+requests环境搭建 首先你得安装Python,然后安装requests模块(第3方模块,安装方法:pip install requests)  基本用法 get 请求(不带参数的) ...