tyvj1086 Elevator

3 篇文章 0 订阅

背景 Background
广东汕头聿怀初中 Train#2 Problem4
描述 Description
现有N种箱子,每种箱子高度H_i,数量C_i。现选取若干箱子堆成一列,且第i种箱子不能放在高度超过A_i的地方。试求最大叠放高度。
输入格式 InputFormat
第一行,一个整数,表示箱子种类N。
接下来N行,每行三个整数,表示H_i,A_i,C_i。
输出格式 OutputFormat
一个整数,表示最大高度。
样例输入 SampleInput [复制数据]
3
7 40 3
5 23 8
2 52 6
样例输出 SampleOutput [复制数据]
48
数据范围和注释 Hint
N <= 400 , H_i <= 100 , C_i <= 10 , A_i <= 40000
来源 Source
Vivian Snow

刷刷水题什么的多好啊

带限制的背包dp。

首先按照a从小到大排序,,因为那些不能举高的放在前面做才行

然后该怎么搞就怎么搞

#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
struct structure{
	int h,c,a;
}dat[4001];
inline bool cmp(const structure &a,const structure &b)
{
	if (a.a<b.a) return 1;
	else if (a.a==b.a)
	{
		if (a.h<b.h) return 1;
		else if (a.h==b.h)
		{
			if (a.c<b.c) return 1;
			else return 0;
		}else return 0;
	}else return 0;
}
bool f[40010];
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	  dat[i].h=read(),dat[i].a=read(),dat[i].c=read();
	sort(dat+1,dat+1+n,cmp);
	f[0]=1;
	for (int i=1;i<=n;i++)
	  for (int j=1;j<=dat[i].c;j++)
	    for (int k=dat[i].a;k>=dat[i].h;k--)
	      f[k]|=f[k-dat[i].h];
	for (int i=40005;i>=0;i--)
	  if (f[i])
	  {
	  	printf("%d",i);
		return 0;
	  }
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值