标签:des style http color os io for art
3 10 10 12 0 10 10 12 1 10 10 11 2 2 10 10 11 1 10 10 11 1 0
24 11
题目大意:
解题思路:有n块砖头,每块砖头有长,宽,高和型号,问你最多建多高?
型号0的特点是:长度>=它下面砖头的长度 且 宽度>=它下面砖头的宽度
型号1的特点是:长度>=它下面砖头的长度 且 宽度>=它下面砖头的宽度 且 面积>=它下面砖头的面积
型号2的特点是:长度>它下面砖头的长度 且 宽度>它下面砖头的宽度
解题代码:先排好序,排序方法贪心的方法,先按长后按宽从小到大排,如果长宽相等就按照型号从大到小排,如果再相等,按照高度从大到小排,高度其实无所谓,但是这样更科学吧。
然后DP的思维,目前有两栋楼如果相同最顶上的砖头相同的话,取高度最大的楼。
#include <iostream>
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1100;
struct nodex{
int l,w,h,id;
friend bool operator < (nodex x,nodex y){
if(x.l!=y.l) return x.l<y.l;
else if(x.w!=y.w) return x.w<y.w;
else if(x.id!=y.id) return x.id>y.id;
else return x.h>y.h;
}
}a[maxn];
struct node{
int num;
long long h;
node(int num0=0,long long h0=0){
num=num0;h=h0;
}
};
long long dp[maxn],n;
void input(){
a[0].l=a[0].w=a[0].h=a[0].id=0;
for(int i=1;i<=n;i++){
scanf("%d%d%d%d",&a[i].l,&a[i].w,&a[i].h,&a[i].id);
if(a[i].w>a[i].l) swap(a[i].w,a[i].l);
}
for(int i=0;i<=n;i++){
dp[i]=-1;
}
sort(a,a+n+1);
}
void solve(){
queue <node> q;
q.push(node(0,0));
dp[0]=0;
for(int i=1;i<=n;i++){
while(!q.empty()){
node s=q.front();
q.pop();
nodex tmp=a[s.num];
if(a[i].id==0){
if(a[i].l>=tmp.l && a[i].w>=tmp.w){
if(s.h+a[i].h>dp[i] ) dp[i]=s.h+a[i].h;
}
}else if(a[i].id==1){
if( (a[i].l>=tmp.l && a[i].w>tmp.w) || (a[i].l>tmp.l && a[i].w>=tmp.w) ){
if(s.h+a[i].h>dp[i] ) dp[i]=s.h+a[i].h;
}
}else{
if(a[i].l>tmp.l && a[i].w>tmp.w){
if(s.h+a[i].h>dp[i] ) dp[i]=s.h+a[i].h;
}
}
}
for(int t=0;t<=n;t++){
if(dp[t]!=-1) q.push(node(t,dp[t]));
}
}
long long ans=0;
for(int i=0;i<=n;i++){
if(dp[i]>ans) ans=dp[i];
}
cout<<ans<<endl;
}
int main(){
while(scanf("%d",&n)!=EOF && n!=0){
input();
solve();
}
return 0;
}
HDU 4001 To Miss Our Children Time (动态规划),布布扣,bubuko.com
HDU 4001 To Miss Our Children Time (动态规划)
标签:des style http color os io for art
原文地址:http://blog.csdn.net/a1061747415/article/details/38362037