当前位置:网站首页>POJ2392 SpaceElevator [DP]
POJ2392 SpaceElevator [DP]
2022-07-07 23:23:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The main idea of the topic : There is a cow going into space , He has many kinds of stones , The height of each stone is hi, But you can't put it ai Height above . And such stones have ci individual Stack these stones . Ask the highest height you can reach . Their thinking : First, sort the data in ascending order . This is a standard multiple backpack problem Why order ? Because only in this way can we get the optimal solution , Suppose the high one is in front at the beginning , Then there are low ones in the back, but you can't choose , Just choose the higher one . In this way, the optimal solution cannot be reached send f[i] The status flag of . Can it reach this height In this way, we can get f[i] in i The maximum value of .
Pay attention here max When assigning the initial value, it should be assigned as 0. Not for -1. Because the answer may be 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;
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116214.html Link to the original text :https://javaforall.cn
边栏推荐
- Cloud native is devouring everything. How should developers deal with it?
- Network security - information query of operating system
- 力扣解法汇总648-单词替换
- Byte hexadecimal binary understanding
- How to generate unique file names
- 十四、数据库的导出和导入的两种方法
- Entity层、DAO层、Service层、Controller层 先后顺序
- ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions
- PMP项目管理考试过关口诀-1
- 13、 System optimization
猜你喜欢
漏洞复现----49、Apache Airflow 身份验证绕过 (CVE-2020-17526)
13、 System optimization
UE4_UE5结合罗技手柄(F710)使用记录
给出一个数组,如 [7864, 284, 347, 7732, 8498],现在需要将数组中的数字拼接起来,返回「最大的可能拼出的数字」
STL标准模板库(Standard Template Library)一周学习总结
2021ICPC上海 H.Life is a Game Kruskal重构树
re1攻防世界逆向
ArcGIS: field assignment_ The attribute table field calculator assigns values to fields based on conditions
Vulnerability recurrence ----- 49. Apache airflow authentication bypass (cve-2020-17526)
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
随机推荐
Solution: prompt "unsupported video format" when inserting avi format video into the message
Network security CSRF
七月第一周
LeeCode -- 6. Zigzag transformation
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
When copying something from the USB flash disk, an error volume error is reported. Please run CHKDSK
网络安全-beef
PMP项目管理考试过关口诀-1
Installing vmtools is gray
Solve the problem of duplicate request resource paths /o2o/shopadmin/o2o/shopadmin/getproductbyid
Unity3d learning notes 4 - create mesh advanced interface
Wechat forum exchange applet system graduation design completion (7) Interim inspection report
opencv scalar传入三个参数只能显示黑白灰问题解决
Archlinux install MySQL
Specific method example of V20 frequency converter manual automatic switching (local remote switching)
Conversion between commonsmultipartfile and file
Installing spss25
HDU 4747 Mex「建议收藏」
sql 数据库执行问题
Wechat forum exchange applet system graduation design (3) background function