当前位置:网站首页>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
边栏推荐
- Network security sqlmap and DVWA explosion
- Wechat forum exchange applet system graduation design (5) assignment
- ./ setup. Insufficient sh permission
- Why does the market need low code?
- FreeLink开源呼叫中心设计思想
- About idea cannot find or load the main class
- GEE(三):计算两个波段间的相关系数与相应的p值
- 网络安全-永恒之蓝
- Bea-3xxxxx error code
- 【编译原理】词法分析设计实现
猜你喜欢

高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏

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

leetcode-520. 检测大写字母-js

Specific method example of V20 frequency converter manual automatic switching (local remote switching)

【编译原理】词法分析设计实现

Matlab-SEIR传染病模型预测

Vulnerability recurrence ----- 49. Apache airflow authentication bypass (cve-2020-17526)

Mysql索引优化实战二

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

V20变频器手自动切换(就地远程切换)的具体方法示例
随机推荐
13、 System optimization
14、 Two methods of database export and import
[microservices SCG] gateway integration Sentinel
Dynamics 365 find field filtering
About idea cannot find or load the main class
三问TDM
Install Fedora under RedHat
Adrnoid开发系列(二十五):使用AlertDialog创建各种类型的对话框
Wechat forum exchange applet system graduation design (3) background function
网络安全-对操作系统进行信息查询
系统架构设计师备考经验分享:论文出题方向
Advantages and disadvantages of rest ful API
Wechat forum exchange applet system graduation design completion (4) opening report
网络安全-联合查询注入
PMP project management exam pass Formula-1
USB(十六)2022-04-28
ROS2专题(03):ROS1和ROS2的区别【01】
USB (十八)2022-04-17
Adrnoid Development Series (XXV): create various types of dialog boxes using alertdialog
FPGA基础篇目录