zoukankan      html  css  js  c++  java
  • 杭电1069_01背包

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

    题目大意:给你n块砖, 每块的长, 宽, 高, 可以任意转换方位, 每种砖都有无限个, 用这些砖叠成塔, 上面的长宽要小于在它下面的长宽, 求塔高最高是多少?

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <cstdlib>
     6 #include <cmath>
     7 #include <set>
     8 #include <map>
     9 #include <vector>
    10 using namespace std;
    11 
    12 struct node
    13 {
    14     int l, w, h;
    15 }a[100];
    16 int cmp(node a, node b)
    17 {
    18     if(a.l != b.l)
    19         return a.l > b.l;
    20     else
    21         return a.w > b.w;
    22 }
    23 int main()
    24 {
    25     int n, x[3], i, j, dp[100], cnt = 0;
    26     while(~scanf("%d", &n))
    27     {
    28         cnt++;
    29         if(n == 0)
    30             break;
    31         for(i = 1; i <= n; i++)
    32         {
    33             scanf("%d %d %d", &x[0], &x[1], &x[2]);
    34             sort(x, x + 3);
    35             a[i * 3].l = x[2], a[i * 3].w = x[1], a[i * 3].h = x[0];
    36             a[i * 3 - 1].l = x[1], a[i * 3 - 1].w = x[0], a[i * 3 - 1].h = x[2];
    37             a[i * 3 - 2].l = x[2], a[i * 3 - 2].w = x[0], a[i * 3 - 2].h = x[1];
    38         }
    39         sort(a + 1, a + n * 3 + 1, cmp);
    40         memset(dp, 0, sizeof(dp));
    41         int sum = 0;
    42         for(i = 1; i <= n * 3; i++)
    43         {
    44             int t = 0;
    45             for(j = 1; j <= i; j++)
    46             {
    47                 if(a[i].l < a[j].l && a[i].w < a[j].w && t < dp[j])
    48                     t = dp[j];
    49             }
    50             dp[i] = t + a[i].h;
    51             if(dp[i] > sum)
    52                 sum = dp[i];
    53         }
    54         printf("Case %d: maximum height = %d
    ", cnt, sum);
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    BroadcastReceiver之发送自定义无序广播
    BroadcastReceiver之应用卸载和安装监听
    Android几种打开SQLite的方法
    BroadcoastReceiver之短信到来监听和获取内容
    BroadcastReceiver之SD的挂载监听
    BroadcastReceive之ip拨号
    Activity之多启动图标
    Uwp Windows10获取设备位置(经纬度)
    DeviceFamily XAML Views(一)
    [SCOI2010]生成字符串
  • 原文地址:https://www.cnblogs.com/luomi/p/5475280.html
Copyright © 2011-2022 走看看