POJ 2392 Space Elevator
2016-03-22 20:30
190 查看
排序+背包。
先对按高度限制从小到大排序,然后做背包即可。0/1背包300多ms过的,可以用完全背包二进制优化。
先对按高度限制从小到大排序,然后做背包即可。0/1背包300多ms过的,可以用完全背包二进制优化。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=400+10; int n; struct X { int h,c,a; }s[maxn]; int dp[400000+10]; int ans; bool cmp(const X&a,const X&b) { return a.a<b.a; } void read() { for(int i=1;i<=n;i++) scanf("%d%d%d",&s[i].h,&s[i].a,&s[i].c); sort(s+1,s+1+n,cmp); } void init() { memset(dp,0,sizeof dp); dp[0]=1; ans=0; } void work() { for(int i=1;i<=n;i++) { for(int j=1;j<=s[i].c;j++) { for(int p=s[i].a;p>=s[i].h;p--) { if(dp[p-s[i].h]==1) { dp[p]=1; ans=max(ans,p); } } } } printf("%d\n",ans); } int main() { while(~scanf("%d",&n)) { read(); init(); work(); } return 0; }
相关文章推荐
- 结对项目— 词频统计(语言C++)
- 【字符串水题】HDU2617Happy 2009
- 解决小米蓝牙耳机无法被检测、无法连接的问题
- 求逆元偷懒方法
- 瑞士轮
- 永远不要打探别人工资
- Alcatraz
- POJ 1017 Packets (贪心)
- 第四周项目5.4—编制递归函数返回第n个Fibnacci数
- leetcode118 & 119. [Array]Pascal's Triangle
- 代码复审
- 链表的操作
- HDU_2604Queuing
- Android 中MD5算法生成字符串
- Android:控件Spinner实现下拉列表
- C++ static静态成员变量和静态成员函数
- lintcode: Construct Binary Tree from Preorder and Inorder Traversal
- 二元谓词的重载2
- 从linux启动到rootfs的挂载分析
- 据廖雪峰python3教程----python学习第五天