设为首页 加入收藏

TOP

ZOJ 1093 Monkey and Banana
2015-11-21 00:56:23 来源: 作者: 【 】 浏览:2
Tags:ZOJ 1093 Monkey and Banana

?

题意:给你n个规格的砖块,告诉你它的长、宽、高,每种规格的砖都有无数块,长宽小的砖块(严格小于,不能等于)可以叠在长宽大的砖块上,问你最多能叠多高。

思路:告诉你一种规格的砖其实给了你三种规格的砖,因为砖是可以翻转的,长宽高可以变化的;

以长为第一变量,宽为第二变量,从大到小排序,这样垫在第n块砖下面的只能从前n-1块选择,选择最大值,累加高度即可。

代码如下:

?

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       const int N = 35; using namespace std; int n; int dp[3*N]; struct node { int x, y, z; bool operator< (const node &rhs) const{ if(x != rhs.x) return x > rhs.x; return y > rhs.y; } }block[3*N]; int main() { int cnt = 1; while(~scanf(%d, &n)) { int a, b, c; if(n == 0) break; for(int i = 0, x, y, z; i < 3 * n; i ++) { scanf(%d%d%d, &x, &y, &z); a = max(max(x, y), z); c = min(min(x, y), z); b = (x + y + z) - (a + c); block[i].x = a, block[i].y = b, block[i].z = c; block[++i].x = a, block[i].y = c, block[i].z = b; block[++i].x = b, block[i].y = c, block[i].z = a; } sort(block, block + 3 * n); int maxn; for(int i = 0; i < 3*n; i++) { maxn = 0; for(int j = 0; j < i; j++) { if(block[j].x > block[i].x && block[j].y > block[i].y && block[j].z > maxn) { maxn = block[j].z; } } block[i].z += maxn; } maxn = 0; for(int i = 0; i < 3*n; i++) { if(maxn < block[i].z) { maxn = block[i].z; } } printf(Case %d: maximum height = %d , cnt, maxn); cnt ++; } return 0; }
     
    
   
  
?
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇leetcode-190-Reverse Bits 下一篇poj 2635 The Embarrassed Crypto..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: