当前位置:网站首页>POJ2392 SpaceElevator [DP]
POJ2392 SpaceElevator [DP]
2022-07-07 21:51:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
题目大意:有一头奶牛要上太空,他有非常多种石头,每种石头的高度是hi,可是不能放到ai之上的高度。而且这样的石头有ci个 将这些石头叠加起来。问可以达到的最高高度。 解题思路:首先对数据进行升序排序。这样才是一个标准的多重背包的问题 为什么要排序? 由于仅仅有这样才干得到最优解,假设一開始就是高的在前面,那么后面有低的却不能选到,就直接选高的去了。这样是不能达到最优解的 使f[i]的状态标记。能否够达到这个高度 这样可以达到取f[i]中i的最大值就可以。
这里要注意max赋初值的时候要赋值为0。不能为-1。由于答案有可能为0
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int type;
int f[44444],usr[44444];
struct Block
{
int h,a,c;
}block[555];
bool cmp(Block a,Block b)
{
return a.a<b.a;
}
int main()
{
scanf("%d",&type);
for(int i=1;i<=type;i++)
{
scanf("%d%d%d",&block[i].h,&block[i].a,&block[i].c);
}
sort(block+1,block+1+type,cmp);
int maxn=0;
f[0]=1;
for(int t=1;t<=type;t++)
{
memset(usr,0,sizeof(usr));
for(int h=block[t].h;h<=block[t].a;h++)
{
if(!f[h] && f[h-block[t].h] && usr[h-block[t].h]+1<=block[t].c)
{
usr[h]=usr[h-block[t].h]+1;
f[h]=1;
maxn=max(h,maxn);
}
}
}
printf("%d\n",maxn);
return 0;
}发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116214.html原文链接:https://javaforall.cn
边栏推荐
- 云原生正在吞噬一切,开发者该如何应对?
- 位运算(Bit Operation)
- Brush question 6
- Freelink open source call center design idea
- Count the top 10 films at the box office and save them in another file
- 网络安全-钓鱼
- JMeter interface automated test read case, execute and write back result
- LDO穩壓芯片-內部框圖及選型參數
- Mitsubishi PLC SLmP (MC) protocol
- Statistical method for anomaly detection
猜你喜欢

JMeter-接口自动化测试读取用例,执行并结果回写

ArcGIS: two methods of attribute fusion of the same field of vector elements

Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid

14、 Two methods of database export and import

LDO voltage stabilizing chip - internal block diagram and selection parameters

Unity3D学习笔记6——GPU实例化(1)

七月第一周

微信论坛交流小程序系统毕业设计毕设(5)任务书

UE4_UE5全景相机

PMP project management exam pass Formula-1
随机推荐
Wechat forum exchange applet system graduation design (2) applet function
The 19th Zhejiang Provincial Collegiate Programming Contest VP记录+补题
七月第一周
云原生数据仓库AnalyticDB MySQL版用户手册
Network security -beef
经纬度PLT文件格式说明
Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid
Installing vmtools is gray
CXF call reports an error. Could not find conduct initiator for address:
About idea cannot find or load the main class
Handling file exceptions
Introduction to redis and jedis and redis things
Statistical method for anomaly detection
FPGA基础篇目录
Dynamics 365 find field filtering
智慧社區和智慧城市之間有什麼异同
JMeter-接口自动化测试读取用例,执行并结果回写
Guessing game (read data from file)
Wechat forum exchange applet system graduation design completion (8) graduation design thesis template
Inftnews | the wide application of NFT technology and its existing problems