B - Monkey and Banana

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description:

Description

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

The researchers have n types of blocks, and an unlimited
supply of blocks of each type. Each type-i block was a rectangular solid
with linear dimensions (xi, yi, zi). A block could be reoriented so
that any two of its three dimensions determined the dimensions of the
base and the other dimension was the height.

They want to make sure that the tallest tower possible by
stacking blocks can reach the roof. The problem is that, in building a
tower, one block could only be placed on top of another block as long as
the two base dimensions of the upper block were both strictly smaller
than the corresponding base dimensions of the lower block because there
has to be some space for the monkey to step on. This meant, for example,
that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.

 

Input

The input file will contain one or more test cases. The first line of each test case contains an integer n,

representing the number of different blocks in the following data set. The maximum value for n is 30.

Each of the next n lines contains three integers representing the values xi, yi and zi.

Input is terminated by a value of zero (0) for n.
 

Output

For each test case, print one line containing the case number (they are
numbered sequentially starting from 1) and the height of the tallest
possible tower in the format "Case case: maximum height = height".
 

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
 

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
 
 
每个格子可以形成6种状态,最多有180种状态,,,,,,,对X,Y作为判断条件进行判断,累加Z值
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. struct node{
  7. int x,y,z;
  8. }que[];
  9. int dp[];
  10. int tot;
  11.  
  12. void addedge(int x,int y,int z){
  13. que[tot].x=x;
  14. que[tot].y=y;
  15. que[tot++].z=z;
  16.  
  17. que[tot].x=x;
  18. que[tot].y=z;
  19. que[tot++].z=y;
  20.  
  21. que[tot].x=y;
  22. que[tot].y=x;
  23. que[tot++].z=z;
  24.  
  25. que[tot].x=y;
  26. que[tot].y=z;
  27. que[tot++].z=x;
  28.  
  29. que[tot].x=z;
  30. que[tot].y=x;
  31. que[tot++].z=y;
  32.  
  33. que[tot].x=z;
  34. que[tot].y=y;
  35. que[tot++].z=x;
  36. }
  37.  
  38. bool cmp(struct node t1,struct node t2){
  39. if(t1.x!=t2.x)
  40. return t1.x>t2.x;
  41. else if(t1.x==t2.x&&t1.y!=t2.y)
  42. return t1.y>t2.y;
  43. else
  44. return t1.z>t2.z;
  45. }
  46.  
  47. int main(){
  48. int n;
  49. int cas=;
  50. while(scanf("%d",&n)!=EOF){
  51. if(!n)
  52. break;
  53. memset(dp,,sizeof(dp));
  54. tot=;
  55. int x,y,z;
  56. for(int i=;i<n;i++){
  57. scanf("%d%d%d",&x,&y,&z);
  58. addedge(x,y,z);
  59. }
  60. sort(que+,que+tot+,cmp);
  61. dp[]=que[].z;
  62. for(int i=;i<tot;i++){
  63. dp[i]=que[i].z;
  64. for(int j=i-;j>=;j--){
  65. if(que[i].x<que[j].x&&que[i].y<que[j].y&&dp[i]<dp[j]+que[i].z)
  66. dp[i]=dp[j]+que[i].z;
  67. }
  68. }
  69. int ans=-;
  70. for(int i=;i<tot;i++)
  71. ans=max(ans,dp[i]);
  72. printf("Case %d: maximum height = %d\n",cas++,ans);
  73. }
  74. return ;
  75. }
 

HDU 1069 dp最长递增子序列的更多相关文章

  1. [DP]最长递增子序列

    #include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...

  2. HDU-1160-FatMouse's Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

  3. hdu 1025 dp 最长上升子序列

    //Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...

  4. poj 1631 Bridging signals (二分||DP||最长递增子序列)

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 ...

  5. HDU 1257 最少拦截系统 最长递增子序列

    HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...

  6. dp之最长递增子序列模板poj3903

    最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS.排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个序列d[1..9] = ...

  7. 动态规划(DP),最长递增子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...

  8. Longest Increasing Subsequences(最长递增子序列)的两种DP实现

    一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn).     二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...

  9. 求解最长递增子序列(LIS) | 动态规划(DP)+ 二分法

    1.题目描述     给定数组arr,返回arr的最长递增子序列. 2.举例     arr={2,1,5,3,6,4,8,9,7},返回的最长递增子序列为{1,3,4,8,9}. 3.解答      ...

随机推荐

  1. Java——列表框:JList

    import java.awt.Container; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import j ...

  2. init.php 建立自己的前端共享文件

    文件位置:include/init.php 1.新建文件lib_xxx.php(lib_liangxin.php) 2.在文件init.php 第74行加入代码 require(ROOT_PATH . ...

  3. ecshop 活动-》红包

    按商品发放:可以给指定某个商品发红包(购买付款,卖家发货后,会自动给买家发送红包:不是买家在付款的时候就自动可以减少红包金额) 按订单金额发放:订单满xx后(卖家发货后,会自动给买家发放红包)

  4. virtualbox中centos系统配置nat+host only上网

    以前一直使用的是virtualbox的桥接模式,桥接模式的特点: 虚拟机和宿主机处于同等地位,就像是一台真实主机一样存在于局域网中,可以分配到一个网络中独立的IP. 虚拟机和宿主机之间能够互访. 如果 ...

  5. localdb

    <connectionStrings> - <add name="default" connectionString="Data Source=.; I ...

  6. OC-copy

    一,堆与栈 1,栈区,stack: 后进先出,由编译器自动分配并释放,一般存放函数的参数值.局部变量 2,堆区,heap:先进先出,由程序员分配和释放 3,全局区,静态区:程序结束后由系统释放, 4, ...

  7. HDInsight 路径问题

    HDInsight中..上传文件的路径是要区分大小写的.. 很变态吧.. 所以项目中要求全部路径使用小写..

  8. Java多线程编程核心技术---对象及变量的并发访问(一)

    synchronized同步方法 "非线程安全"其实会在多个线程对同一个对象中的实例变量进行并发访问时发生,产生的后果就是"脏读",也就是渠道的数据其实是被更改 ...

  9. Mysql 常用函数

    统计函数: count()   统计记录条数,如 select count(*) from stu; sum()     统计记录字段的和,如select sum(salary) from emp; ...

  10. 网页JQ基础之jq-隐藏以及显示特效

    简单的 隐藏以及显示的 JQ 的代码如下: <!DOCTYPE html> <html> <head> <script src="/jquery/j ...