hdu 1069 动态规划

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6. struct node
  7. {
  8. int x, y, z, h;
  9. };
  10. bool cmp(node a, node b)
  11. {
  12. return a.x*a.y < b.x*b.y;
  13. }
  14. void change(int &a, int &b, int &c)
  15. {
  16. int t;
  17. if(a>b) {t=a; a=b; b=t;}
  18. if(a>c) {t=a; a=c; c=t;}
  19. if(b>c) {t=b; b=c; c=t;}
  20. }
  21. int main()
  22. {
  23. int n;
  24. int T =1;
  25. while(scanf("%d", &n)!=EOF && n)
  26. {
  27. node num[500];
  28. //int dp[500];
  29. //memset(dp, 0, sizeof(dp) );
  30. int flag =0;
  31. for(int i=0; i<n; i++)
  32. {
  33. int a, b, c;
  34. scanf("%d%d%d", &a, &b, &c);
  35. change(a, b, c);
  36. num[flag].x = a; num[flag].y = b; num[flag++].z = c;
  37. num[flag].x = a; num[flag].y = c; num[flag++].z = b;
  38. num[flag].x = b; num[flag].y = c; num[flag++].z = a;
  39. }
  40. sort(num, num+flag, cmp);
  41. int all = 0;
  42. num[0].h = num[0].z;
  43. for(int i=0; i<flag; i++)
  44. {
  45. int max = 0;
  46. for(int j=0; j<i; j++)
  47. {
  48. if(num[j].x < num[i].x && num[j].y < num[i].y && max < num[j].h)
  49. max = num[j].h;
  50. }
  51. num[i].h = max + num[i].z;
  52. }
  53. for(int i=0; i<flag; i++)
  54. if(all < num[i].h)
  55. all = num[i].h;
  56. printf("Case %d: maximum height = %d\n",T++,all);
  57. }
  58. return 0;
  59. }

来自为知笔记(Wiz)

附件列表

时间: 2024-08-01 10:44:10

hdu 1069 动态规划的相关文章

C - Monkey and Banana HDU 1069( 动态规划+叠放长方体)

C - Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1069 Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof

HDU 1069 Monkey and Banana dp 题解

HDU 1069 Monkey and Banana 题解 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种长方体,计算,最高能堆多高.要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽. 输入输出 开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量 输出使用这些在满足条件的情况下能够摆放的最大高度 解

[2016-03-30][HDU][1069][Monkey and Banana]

时间:2016-03-27 15:19:40 星期日 题目编号:[2016-03-30][HDU][1069][Monkey and Banana] 题目大意:给定n种积木无限个,问这些积木最大能叠多高,上面的积木长宽必须严格小于下面的积木 分析: dp[i]表示第i个积木在顶部时候的最大高度,那么dp[i] = max(dp[i],dp[j] + h[i]);?ji能放在j上面?ji能放在j上面 初始条件就是长宽最大的高度是它自己, #include <algorithm> #include

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

---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13003    Accepted Submission(s): 6843 Problem Description A group of researchers are designing an experiment to te

HDU 1069&amp;&amp;HDU 1087 (DP 最长序列之和)

H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Appoint description:  System Crawler  (2015-11-18) Description Nowadays, a kind of chess game called “Su

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

Monkey and Banana Problem 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

FatMouse&#39;s Speed hdu 1160(动态规划,最长上升子序列+记录路径)

http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意:现给出老鼠的体重与速度,要求你找出符合要求的最长子序列.       要求是 W[m[1]] < W[m[2]] < ... < W[m[n]](体重) && S[m[1]] > S[m[2]] > ... > S[m[n]] (速度) 分析:有两个变量的话比较不好控制,自然需要先排序.再仔细思考的话,觉得和之前做的防御导弹有点类似,都是求最多能有几个符合

HDU 1069 dp最长递增子序列

B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1069 Appoint description: Description A group of researchers are designing an experiment to test the IQ of a monkey. They wi

HDU 1069 Monkey and Banana (动规)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7248    Accepted Submission(s): 3730 Problem Description A group of researchers are designing an experiment to test the IQ of a