当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
opencv scalar传入三个参数只能显示黑白灰问题解决
14、 Two methods of database export and import
Network security - phishing
深入理解Mysql锁与事务隔离级别
Adrnoid Development Series (XXV): create various types of dialog boxes using alertdialog
USB(十四)2022-04-12
Bea-3xxxxx error code
2021ICPC上海 H.Life is a Game Kruskal重构树
[microservices SCG] gateway integration Sentinel
Network security - information query of operating system
648. 单词替换
Wechat forum exchange applet system graduation design completion (8) graduation design thesis template
Add data analysis tools in Excel
leetcode-520. Detect capital letters -js
【编译原理】词法分析设计实现
Quelles sont les similitudes et les différences entre les communautés intelligentes et les villes intelligentes?
十三、系统优化
When copying something from the USB flash disk, an error volume error is reported. Please run CHKDSK
网络安全-sqlmap与DVWA爆破
USB (十八)2022-04-17