zoukankan      html  css  js  c++  java
  • HDU 1069 Monkey and Banana (动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069

    简单记录一下

    思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可

    转移方程 dp[i]=max(dp[i],dp[t]+a[i].z)  //dp里存的是高度,a[i].z是第i个的高度
     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <string>
     6 #include <stack>
     7 #include <queue>
     8 #include <cmath>
     9 #define ll long long
    10 #define pi 3.1415927
    11 #define inf 0x3f3f3f3f
    12 using namespace std;
    13 struct node {
    14     int x,y,z;
    15 }a[200];
    16 bool cmp (node x, node y)
    17 {
    18     if (x.x==y.x)
    19         return x.y<y.y;
    20     return x.x<y.x;
    21 }
    22 int dp[200];
    23 int main ()
    24 {
    25     int n,m,i,t,sum,j=0,k;
    26     while(cin>>n)
    27     {
    28         j++;
    29         if(n==0)
    30             break;
    31         k=0;
    32         for(i=0;i<n;++i)
    33         {
    34             int x,y,z;
    35             cin>>x>>y>>z;
    36             if(x==y==z)
    37                 a[k].x=x, a[k].y=y, a[k++].z=z;
    38             else if (x==y)
    39                 a[k].x=x, a[k].y=y, a[k++].z=z,
    40                 a[k].x=x, a[k].y=z, a[k++].z=y,
    41                 a[k].x=z, a[k].y=x, a[k++].z=y;
    42             else if (x==z)
    43                 a[k].x=x, a[k].y=y, a[k++].z=z,
    44                 a[k].x=x, a[k].y=z, a[k++].z=y,
    45                 a[k].x=y, a[k].y=x, a[k++].z=z;
    46             else if (y==z)
    47                 a[k].x=x, a[k].y=y, a[k++].z=z,
    48                 a[k].x=z, a[k].y=y, a[k++].z=x,
    49                 a[k].x=y, a[k].y=x, a[k++].z=z;
    50             else
    51                 a[k].x=x, a[k].y=y, a[k++].z=z,
    52                 a[k].x=x, a[k].y=z, a[k++].z=y,
    53                 a[k].x=y, a[k].y=x, a[k++].z=z,
    54                 a[k].x=y, a[k].y=z, a[k++].z=x,
    55                 a[k].x=z, a[k].y=y, a[k++].z=x,
    56                 a[k].x=z, a[k].y=x, a[k++].z=y;
    57         }
    58         sort(a,a+k,cmp);
    59         for(i=0;i<k;++i)
    60             dp[i]=a[i].z;
    61         int maxs=0;
    62         for(i=1;i<k;++i)
    63             for(t=0;t<i;++t)
    64         {
    65             if(a[i].x>a[t].x &&a[i].y>a[t].y){
    66                 dp[i]=max(dp[i],dp[t]+a[i].z);
    67                 maxs=max(maxs,dp[i]);
    68             }
    69         }
    70         cout<<"Case "<<j<<": maximum height = "<<maxs<<endl;
    71     }
    72 
    73 
    74     return 0;
    75 }
  • 相关阅读:
    http服务读取配置文件,交叉编译
    etcd增删改查
    初始
    20141017--类型String类
    20141017--异常语句try-catch
    20141017--循环语句whlie,do
    20141017--循环语句for 穷举
    20141016--for 菱形
    20141016--for 兔子
    20141015--for语句1
  • 原文地址:https://www.cnblogs.com/blowhail/p/11951861.html
Copyright © 2011-2022 走看看