zoukankan      html  css  js  c++  java
  • HDU4001To Miss Our Children Time【dp】

    大意:有三种长方体木块,只有满足如下关系一个木块才可以放在另一个的上面

    We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length and width which lies under the block. Here are some blocks.

    问最大高度

    分析  因为l和w都是一次递增的  所以只要把其排好序那么就可以dp了  后面的只会被前面的状态所决定

    代码:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 const long long maxn = 1005;
     8 
     9 struct Node {
    10     long long l, w, h, d;
    11 }node[maxn];
    12 long long dp[maxn];
    13 bool cmp(Node n1, Node n2) {
    14     if(n1.l != n2.l) return n1.l < n2.l;
    15     else if(n1.w != n2.w) return n1.w < n2.w;
    16     return n1.d > n2.d;
    17 }
    18 
    19 int main() {
    20     long long n;
    21     while(scanf("%I64d",&n) ) {
    22         if(n == 0) break;
    23         memset(dp, 0, sizeof(dp));
    24         for(long long i = 1; i <= n; i++) {
    25             scanf("%I64d %I64d %I64d %I64d",&node[i].l, &node[i].w, &node[i].h, &node[i].d);
    26             if(node[i].l < node[i].w) swap(node[i].l, node[i].w);
    27         }
    28         sort(node + 1, node + 1 + n, cmp);
    29         for(long long i = 1; i <= n; i++) {
    30             dp[i] = node[i].h;
    31         }
    32         for(long long i = 1; i <= n; i++) {
    33             for(long long j = 1; j < i; j++) {
    34                 if(node[i].d == 0) {
    35                     if(node[i].l >= node[j].l && node[i].w >= node[j].w) {
    36                         dp[i] = max(dp[i], dp[j] + node[i].h);
    37                     } 
    38                 } else if(node[i].d == 1) {
    39                     if((node[i].l >= node[j].l && node[i].w > node[j].w) || (node[i].l > node[j].l && node[i].w >= node[j].w)) {
    40                         dp[i] = max(dp[i], dp[j] + node[i].h);
    41                     }
    42                 } else {
    43                     if(node[i].l > node[j].l && node[i].w > node[j].w) {
    44                         dp[i] = max(dp[i], dp[j] + node[i].h);
    45                     }
    46                 }
    47             }
    48         }
    49         long long ans = 0;
    50         for(long long i = 1; i <= n; i++) ans = max(ans, dp[i]);
    51         printf("%I64d
    ", ans);
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    视图容器组件使用
    组件的学习
    伸展树
    二叉搜索树
    二叉树
    笛卡尔树
    二叉堆
    vim配置
    使用vim-pathogen 进行插件管理
    C/C++中的变量和静态变量
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/4107914.html
Copyright © 2011-2022 走看看