当前位置:网站首页>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
边栏推荐
- Why does the market need low code?
- 树后台数据存储(採用webmethod)[通俗易懂]
- 违法行为分析1
- HDU 4747 Mex「建议收藏」
- 网格(Grid)
- Puce à tension stabilisée LDO - schéma de bloc interne et paramètres de sélection du modèle
- Network security - phishing
- Spark 离线开发框架设计与实现
- Advantages and disadvantages of rest ful API
- 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
猜你喜欢

Mysql索引优化实战一

2021ICPC上海 H.Life is a Game Kruskal重构树
![MATLAB signal processing [Q & A essays · 2]](/img/be/0baa92767c3abbda9b0bff47cb3a75.png)
MATLAB signal processing [Q & A essays · 2]
![[microservices SCG] gateway integration Sentinel](/img/f3/410d7228b4b253ebf41015a785099f.png)
[microservices SCG] gateway integration Sentinel

Wechat forum exchange applet system graduation design (2) applet function

Installing spss25

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

Wechat forum exchange applet system graduation design (3) background function

十三、系统优化

经纬度PLT文件格式说明
随机推荐
Freelink open source call center design idea
648. 单词替换
Wechat forum exchange applet system graduation design (5) assignment
Binary tree
In the field of software engineering, we have been doing scientific research for ten years!
Force deduction solution summary 648 word replacement
网络安全-CSRF
Gee (IV): calculate the correlation between two variables (images) and draw a scatter diagram
Matlab 信号处理【问答随笔·2】
The 19th Zhejiang Provincial College Programming Contest 2022 f.easyfix chairman tree
JS get the key and value of the object
云原生正在吞噬一切,开发者该如何应对?
Unity3d learning notes 5 - create sub mesh
2021ICPC上海 H.Life is a Game Kruskal重构树
Experience sharing of system architecture designers in preparing for the exam: the direction of paper writing
Turbo introder common scripts
Quelles sont les similitudes et les différences entre les communautés intelligentes et les villes intelligentes?
Specific method example of V20 frequency converter manual automatic switching (local remote switching)
【微服务|SCG】gateway整合sentinel
The 19th Zhejiang Provincial College Programming Contest VP record + supplementary questions