当前位置:网站首页>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
边栏推荐
- 经纬度PLT文件格式说明
- Statistical method for anomaly detection
- 位运算(Bit Operation)
- UE4_UE5全景相机
- Wechat forum exchange applet system graduation design completion (8) graduation design thesis template
- 14、 Two methods of database export and import
- Ros2 topic (03): the difference between ros1 and ros2 [01]
- 违法行为分析1
- STL标准模板库(Standard Template Library)一周学习总结
- Brush question 5
猜你喜欢

Talk about the design and implementation logic of payment process

Inftnews | the wide application of NFT technology and its existing problems

LeeCode -- 6. Z 字形变换

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

Technology at home and abroad people "see" the future of audio and video technology

Wechat forum exchange applet system graduation design (5) assignment

leetcode-520. 检测大写字母-js
![Ros2 topic (03): the difference between ros1 and ros2 [02]](/img/12/244ea30b5b141a0f47a54c08f4fe9f.png)
Ros2 topic (03): the difference between ros1 and ros2 [02]

Lecture 30 linear algebra Lecture 5 eigenvalues and eigenvectors

In the field of software engineering, we have been doing scientific research for ten years!
随机推荐
三问TDM
CAIP2021 初赛VP
Guessing game (read data from file)
网络安全-联合查询注入
Vs extension tool notes
The 19th Zhejiang Provincial Collegiate Programming Contest VP记录+补题
Adrnoid Development Series (XXV): create various types of dialog boxes using alertdialog
What are the similarities and differences between smart communities and smart cities
./ setup. Insufficient sh permission
Gee (IV): calculate the correlation between two variables (images) and draw a scatter diagram
Ros2 topic (03): the difference between ros1 and ros2 [02]
深入理解Mysql锁与事务隔离级别
Coreseek: the second step is index building and testing
UE4_UE5结合罗技手柄(F710)使用记录
经纬度PLT文件格式说明
智慧社区和智慧城市之间有什么异同
VS扩展工具笔记
Wechat forum exchange applet system graduation design completion (4) opening report
Conversion between commonsmultipartfile and file
微信论坛交流小程序系统毕业设计毕设(1)开发概要