POJ 2392 Space Elevator
来源:互联网 发布:金融富豪 知乎 编辑:程序博客网 时间:2024/05/21 18:44
题意:帮牛建宇宙电梯,现在有很多种砖块,每种砖都有自己的高度和高度上限以及数量,高度上限是说这种砖不能搭在高于这个高度的地方。现在要求能达到的最大高度。
做法:dp,跟POJ1742做法很像。
dp[j] = 1 代表高度j能拼成,user[j]用来存到达j高度时某同种砖块使用的数量。高度上限小的放在下面,所以对高度上限排序,再DP。
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>struct p{ int h,a,c;}x[410];bool comp(p a1, p a2){ return a1.a<a2.a;}bool dp[40010];int user[40010];using namespace std;int main(){ int n; while(~scanf("%d",&n)) { int ans = 0; for(int i = 0 ; i < n ; i ++) { scanf("%d%d%d",&x[i].h,&x[i].a,&x[i].c); } sort(x,x+n,comp);//排序 memset(dp,false,sizeof(dp)); dp[0] = true; for(int i = 0 ; i < n ; i ++) { memset(user,0,sizeof(user)); for(int j = x[i].h ; j <= x[i].a ; j++) { if(!dp[j]&&dp[j-x[i].h]&&user[j-x[i].h]<x[i].c)高度j未到达过,并且能从其他状态转移,并且该种砖块数量没超出上限。 { dp[j] = true; user[j] = user[j - x[i].h] + 1 ; ans = max(ans , j);//寻找最大的高度。 } } } printf("%d\n",ans); } return 0;}
0 0
- POJ 2392 Space Elevator
- poj 2392 Space Elevator
- POJ 2392 Space Elevator
- poj 2392 Space Elevator
- POJ 2392 Space Elevator
- poj 2392 Space Elevator
- POJ-2392-Space Elevator
- poj 2392 Space Elevator
- poj 2392--Space Elevator
- poj 2392 Space Elevator
- POJ 2392 Space Elevator
- POJ 2392 Space Elevator
- poj 2392 Space Elevator
- poj 2392 Space Elevator
- poj 2392 space elevator
- POJ 2392 Space Elevator
- POJ 2392 Space Elevator
- POJ 2392 Space Elevator
- ZOJ 3490 String Successor
- 我对于调用对象和基本变量类型内存的运行机制理解
- BZOJ 2125 最短路 静态仙人掌
- Java Tomcat SSL 服务端/客户端双向认证
- 2015年网络红包攻略
- POJ 2392 Space Elevator
- ZOJ 3326 An Awful Problem
- CSS学习笔记
- UVa 11040 - Add bricks in the wall(规律)
- java基础--数组
- Ojbective-C为什么不用@public
- HDU 2483 Counting square
- [oj.leetcode] #174 - Dungeon Game 一次特别的DP之旅
- hdu 1026 Ignatius and the Princess I