POJ3624 Charm Bracelet 01背包裸题
来源:互联网 发布:js 浏览 后退不刷新 编辑:程序博客网 时间:2024/05/07 11:00
Description
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6
1 4
2 6
3 12
2 7
Sample Output
23
Source
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
Input
* Line 1: Two space-separated integers: N and M
* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6
1 4
2 6
3 12
2 7
Sample Output
23
Source
USACO 2007 December Silver
#include <iostream>#include <cstdio>#include <map>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <cstring>#include <string>using namespace std;#define INF 0x3f3f3f3ftypedef long long LL;int dp[13000];int main(){ int n,w; int wei[3500],pri[3500]; while(~scanf("%d%d",&n,&w)){ for(int i=1;i<=n;i++){ scanf("%d%d",&wei[i],&pri[i]); } memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++){ for(int j=w;j-wei[i]>=0;j--){ dp[j]=max(dp[j],dp[j-wei[i]]+pri[i]); } } printf("%d\n",dp[w]); } return 0;}
0 0
- 【POJ3624】Charm Bracelet 01背包裸题
- POJ3624 Charm Bracelet 01背包裸题
- POJ3624:Charm Bracelet【01背包】
- POJ3624 Charm Bracelet 【01背包】
- 【POJ3624】Charm Bracelet(01背包)
- POJ3624 - Charm Bracelet(01背包)
- poj3624 Charm Bracelet 01背包
- poj3624-Charm Bracelet(01背包模板题)
- poj3624(Charm Bracelet + 赤裸01背包)
- poj3624 Charm Bracelet DP 01背包问题
- Charm Bracelet(poj3624)(01背包)
- POJ3624 Charm Bracelet (01背包)
- POJ3624 Charm Bracelet(01背包)
- poj3624 Charm Bracelet(01背包)
- POJ3624 Charm Bracelet(01背包问题)
- POJ3624 Charm Bracelet(典型01背包问题)
- (poj3624)Charm Bracelet(01背包)
- POJ3624 Charm Bracelet(01背包问题)
- 问题记录:hadoop集群提交job时出现Exception in thread "main" java.io.IOException: Error opening job jar:
- 删掉win上顽固文件与文件夹
- ACM知识点 之 知识架构和要点分析
- 关于利用ajax上传文件的心得
- HDU 5256 序列变换
- POJ3624 Charm Bracelet 01背包裸题
- 混合高斯模型
- layout_marginBottom的使用(将VIEW放置在布局底部)
- java实现在指定目录下的特定文件中查找特定字符串集
- jetbrains全家桶的配置
- 下半年学习计划
- BZOJ 1295 最长距离(最短路)
- Effective c++ 阅读笔记1
- mysql创建用户,授权