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 ",T++,all);
  57. }
  58. return 0;
  59. }





附件列表

    原文地址:https://www.cnblogs.com/sober-reflection/p/bea0c92ceea2402b1073fb6fc0a959fa.html