当前位置:网站首页>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
边栏推荐
- Wechat forum exchange applet system graduation design completion (6) opening defense ppt
- The text editor of markdown class should add colors to fonts (including typora, CSDN, etc.)
- USB(十四)2022-04-12
- Installing vmtools is gray
- Redhat下安装fedora
- About idea cannot find or load the main class
- Gee (III): calculate the correlation coefficient between two bands and the corresponding p value
- leetcode-520. 检测大写字母-js
- Oracle-数据库的备份与恢复
- Wechat forum exchange applet system graduation design completion (1) development outline
猜你喜欢

Installing spss25

微信论坛交流小程序系统毕业设计毕设(2)小程序功能

微信论坛交流小程序系统毕业设计毕设(4)开题报告

Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night

Lecture 30 linear algebra Lecture 5 eigenvalues and eigenvectors

PMP项目管理考试过关口诀-1

深入理解Mysql锁与事务隔离级别

Oracle-数据库的备份与恢复

ROS2专题(03):ROS1和ROS2的区别【01】

LDO穩壓芯片-內部框圖及選型參數
随机推荐
Why does the market need low code?
CXF call reports an error. Could not find conduct initiator for address:
网络安全-burpsuit
Solution: prompt "unsupported video format" when inserting avi format video into the message
网络安全-安装CentOS
LDO穩壓芯片-內部框圖及選型參數
VS扩展工具笔记
网络安全-钓鱼
js 获取对象的key和value
Tree background data storage (using webmethod) [easy to understand]
Coreseek: the second step is index building and testing
ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions
在软件工程领域,搞科研的这十年!
turbo intruder常用脚本
Unity3D学习笔记6——GPU实例化(1)
成年人只有一份主业是要付出代价的,被人事劝退后,我哭了一整晚
Wechat forum exchange applet system graduation design (2) applet function
What are the similarities and differences between smart communities and smart cities
leetcode-520. 检测大写字母-js
Vulnerability recurrence ----- 49. Apache airflow authentication bypass (cve-2020-17526)