博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4001 To Miss Our Children Time
阅读量:7205 次
发布时间:2019-06-29

本文共 2464 字,大约阅读时间需要 8 分钟。

题意: 有n 个砖块,有不同的长宽高,分为三种类型,要求是:

       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.

       问最多可以堆成多高的积木

分析:之间按题意DP

        先排序,排序先 按len 再按 wi 再按 d

        dp[i]  表示前 i 块砖的最大高度.

 

#include 
#include
#include
using namespace std;#define clr(x)memset(x,0,sizeof(x))long long max(long long a,long long b){ return a>b?a:b;}struct node{ int wi, le, th, d;}a[1005];bool cmp(node a,node b){ if(a.le != b.le) { return a.le < b.le; } if(a.wi != b.wi) { return a.wi < b.wi; } return a.d > b.d;}long long dp[1005];int main(){ int n, i, j; while (scanf("%d",&n),n) { //a[0].le = a[0].wi = 0; for(i=1; i<=n; i++){ scanf("%d %d %d %d",&a[i].le,&a[i].wi,&a[i].th,&a[i].d); if(a[i].le > a[i].wi) { int tmp = a[i].le; a[i].le = a[i].wi; a[i].wi = tmp; } } sort(a+1,a+n+1,cmp); clr(dp); long long res = a[1].th; for(i=1; i<=n; i++) { dp[i] = a[i].th; res = max(res,dp[i]); } for(i=1; i<=n; i++) { //dp[i] = dp[i-1]; for(j=1; j< i; j++) { if(a[i].d == 0) { if(a[j].le <= a[i].le && a[j].wi <= a[i].wi) dp[i] = max(dp[i],dp[j]+a[i].th); } else if(a[i].d == 1) { if(a[j].le <= a[i].le && a[j].wi <= a[i].wi && (a[j].le < a[i].le || a[j].wi < a[i].wi)) dp[i] = max(dp[i],dp[j]+a[i].th);// printf("%d__%d\n",i,dp[i]); } else if(a[i].d == 2) { if(a[j].le < a[i].le && a[j].wi < a[i].wi) dp[i] = max(dp[i],dp[j]+a[i].th); } } res = max(res,dp[i]); } printf("%I64d\n",res); } return 0;}

 

 

 

转载于:https://www.cnblogs.com/dream-wind/archive/2012/11/03/2752075.html

你可能感兴趣的文章
centos下安装升级python到python3.5
查看>>
数据结构实验之排序二:交换排序
查看>>
【视频教程】Mini6410/Tiny6410的国嵌视频教程光盘,总共五张
查看>>
桶排序
查看>>
追MM与Java的23种设计模式[转]
查看>>
线程 2
查看>>
[C#][控件]文本类控件
查看>>
[Multimedia][MPEG2]MPEG-2系统原理
查看>>
背包九讲(转)
查看>>
HDU5988 Coding Contest(浮点费用流)
查看>>
css3文字溢出显示省略号
查看>>
Rugy 茶余饭后
查看>>
Linux shell中运行命令后加上字符“&”的作用
查看>>
MySQL存储引擎对比
查看>>
[Android Pro] AsyncTaskLoader vs AsyncTask
查看>>
[Linux] du-查看文件夹大小-并按大小进行排序
查看>>
转:numpy数据集练习——鸢尾花数据集
查看>>
把wcf服务,改成restful方式,以及吐槽
查看>>
SpatiaLite 各版本数据库差异
查看>>
Python变量和数据类型
查看>>