POJ 3624 Charm Bracelet
来源:互联网 发布:杭州富谦网络 编辑:程序博客网 时间:2024/05/01 16:50
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 weightWi (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 61 42 63 122 7
Sample Output
23
Source
f[v]=max(f[v],f[v-a[i].w]+a[i].d);
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n,m;int f[15000];struct thing{ int w; int d;}a[5000];int main(){ //freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].w,&a[i].d); f[i]=0; } for(int i=1;i<=n;i++) { for(int v=m;v>=a[i].w;v--) { f[v]=max(f[v],f[v-a[i].w]+a[i].d); } } //for(int i=1;i<=m;i++)printf("%d\n",f[i]); printf("%d\n",f[m]); return 0;}
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- POJ 3624 Charm Bracelet
- POJ 3624 Charm Bracelet
- Poj 3624 Charm Bracelet
- poj 3624 Charm Bracelet
- POJ 3624 Charm Bracelet
- POJ-3624-Charm Bracelet
- POJ 3624 Charm Bracelet
- poj 3624 charm bracelet
- poj 3624:Charm Bracelet
- POJ--3624--Charm Bracelet
- poj 3624 Charm Bracelet
- POJ 3624 Charm Bracelet
- POJ 3624 Charm Bracelet
- POJ-3624 Charm Bracelet
- CodeForces 275C k-Multiple Free Set
- c数组实现线性表储存。
- Python3.2官方文档翻译--类总介绍
- PullToRefresh开源项目详解以及universal-image-loader的使用(一)
- 互联网系统架构的演进
- POJ 3624 Charm Bracelet
- 《设计模式之禅》六大设计原则(二)里氏替换原则
- 泛型类型
- hibernate集合映射inverse和cascade详解
- 恶心的www.3600.com
- 超级简单JS网页倒计时代码
- 模板显式实例化 explicit template instantiation
- [转]Java中常用的加密方法(JDK)
- 算法实验 层序列表问题(二叉树)