POJ 2392 初涉多重背包
来源:互联网 发布:php class 实例 编辑:程序博客网 时间:2024/05/22 22:55
题意:有K种石头,每种石头的高度为H,个数为Q,放置高度不能超过C。问这些石头最高的可达高度是多少。
裸的多重背包。
对于N种,K件的多重背包可以转换成∑ki的01背包。
假设不存在限制C时,则先放A种还是先放B中对结果无影响。当添加上限制条件C时,应该让C小的在下面。故在进行01背包前要将C排序。
#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <cmath>#include <algorithm>#include <stack>#define LL long long#define ULL unsigned long long#define PI (acos(-1.0))#define EPS (1e-10)#pragma comment(linker,"/STACK:102400000,1024000")using namespace std;struct N{ int w,v,q;}c[410];bool acc[40010];bool cmp(N c1, N c2){ return c1.w < c2.w;}int main(){ int n,i,j,k; scanf("%d",&n); for(i = 0;i < n; ++i) { scanf("%d %d %d",&c[i].v,&c[i].w,&c[i].q); } sort(c,c+n,cmp); memset(acc,false,sizeof(acc)); acc[0] = true; int Max = 0; for(i = 0;i < n;++i) { for(j = 0;j < c[i].q; ++j) { for(k = c[i].w; k >= c[i].v; --k) { if(acc[k-c[i].v]) { acc[k] = true; Max = max(Max,k); } } } } printf("%d\n",Max); return 0;}
0 0
- POJ 2392 初涉多重背包
- 【多重背包】POJ 2392
- poj 2392 多重背包
- poj 2392 多重背包
- POJ 2392【多重背包】
- 多重背包问题 POJ 2392
- POJ 2392(多重背包)
- poj 2392 Space Elevator 多重背包
- poj 2392 Space Elevator(多重背包变形)
- POJ 2392 Space Elevator [DP 多重背包]
- POJ 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator(排序+多重背包)
- POJ 2392 Space Elevator (多重背包问题)
- POJ 2392 Space Elevator 多重背包
- Poj 2392 多重背包变形(模板)
- POJ 2392 Space Elevator (多重背包+优化)
- poj 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator(多重背包)
- Phpcms V9 调用全站最新文章的方法
- 网卡驱动8-MII接口以及linux内核对MII的支持
- 14年春面试前学习计划(一)
- 给定整数数组,相邻两个之间之差为1或者-1,求给定数在数组中的位置
- 计算机应用和软件开发
- POJ 2392 初涉多重背包
- fpm简介
- Ext Js技术之面板的初步使用
- 】The application’s PagerAdapter changed the adapter’s contents without calling PagerAdapter#notifyDa
- javascript不一样的写法
- Chromium contentshell启动分析之sandox process创建历程(chromium:tag28)
- 利用over开窗函数取第一条记录
- 寒假训练--01背包完全背包--小P的故事——神奇的饭卡
- 输入数据加速 scan_d();