poj2392 多重背包
//Accepted 868 KB 188 ms
//多重背包
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
;
int dp[imax_v];
int n;
struct node
{
int weight,c,a;
}f[imax_n];
//按a排序,考虑我们在dp时采用的是倒推,所以我们需要先计算出a较小的时候的情况
int cmp(node x,node y)
{
return x.a<y.a;
}
int max(int a,int b)
{
return a>b?a:b;
}
void zeroOnePack(int weight,int value,int v)
{
for (int j=v;j>=weight;j--)
{
dp[j]=max(dp[j],dp[j-weight]+value);
}
}
void completePack(int weight,int value,int v)
{
for (int j=weight;j<=v;j++)
{
dp[j]=max(dp[j],dp[j-weight]+value);
}
}
void multiplePack(int weight,int value,int amount,int v)
{
;
if (amount*weight>=v)
{
completePack(weight,value,v);
return ;
}
while (k<amount)
{
zeroOnePack(k*weight,k*value,v);
amount-=k;
k<<=;
}
zeroOnePack(amount*weight,amount*value,v);
}
void Dp()
{
memset(dp,,sizeof(dp));
;i<=n;i++)
{
multiplePack(f[i].weight,f[i].weight,f[i].c,f[i].a);
}
;
;i<=;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
;i<=n;i++)
scanf("%d%d%d",&f[i].weight,&f[i].a,&f[i].c);
sort(f+,f+n+,cmp);
Dp();
}
;
}
poj2392 多重背包的更多相关文章
- poj2392 Space Elevator(多重背包)
http://poj.org/problem?id=2392 题意: 有一群牛要上太空.他们计划建一个太空梯-----用一些石头垒.他们有K种不同类型的石头,每一种石头的高度为h_i,数量为c_i,并 ...
- dp之多重背包poj2392
题意:有k种石头,高为hi,在不超过ai的高度下,这种石头可以放置,有ci种这个石头,求这些石头所能放置的最高高度......... 思路:以往的什么硬币种数,最大硬币数之类的,他们的硬币都已经是排好 ...
- 洛谷P1782 旅行商的背包[多重背包]
题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能 ...
- HDU 2082 找单词 (多重背包)
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- (多重背包+记录路径)Charlie's Change (poj 1787)
http://poj.org/problem?id=1787 描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...
- 单调队列优化DP,多重背包
单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...
随机推荐
- Graph-tool简介 - wiki
graph-tool is a Python module for manipulation and statistical analysis of graphs[disambiguation nee ...
- 复杂TableView在iOS上的性能优化
声明:本文翻译自<iOS performance optimization>,原文作者 Khang Vo.翻译本文纯属为了技术交流的目的,并不具有任何的商业性质,也不得利用本文内容进行商业 ...
- maven工程打包成runnable的jar包,拷贝资源和依赖jar包
eclipse下新建maven工程,生成runnable的jar包.之前一直是手动拷贝依赖的jar包和资源文件,烦得要死.上网可劲查了一下.解决方案如下. 在pom的配置文件中做如下配置: <b ...
- python 写入csv文件
import csv fieldnames = ['Column1', 'Column2', 'Column3', 'Column4'] rows = [{'Column1': '0', 'Col ...
- Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(一)
pom.xml配置 <dependencies> <!-- hibernate begin --> <dependency> <groupId>org. ...
- Windows NT访问权限
#define SECTION_QUERY 0x0001 #define SECTION_MAP_WRITE 0x0002 #define SECTION_MAP_READ 0x0004 #defin ...
- nyoj-----284坦克大战(带权值的图搜索)
坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Many of us had played the game "Battle city" ...
- 133. Clone Graph 138. Copy List with Random Pointer 拷贝图和链表
133. Clone Graph Clone an undirected graph. Each node in the graph contains a label and a list of it ...
- Java 集合系列 16 HashSet
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- Java 集合系列 13 WeakHashMap
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...