博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3624 Charm Bracelet
阅读量:5268 次
发布时间:2019-06-14

本文共 1306 字,大约阅读时间需要 4 分钟。

  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 61 42 63 122 7

Sample Output

23 01背包:  直接套模板
#include 
#include
using namespace std;int main(){ int w[35000],v[35000],f[35000]; int n,m,i,j; cin>>n>>m; for(i=0;i
>w[i]>>v[i]; for(i=0;i
=w[i];j--) f[j]=max(f[j],f[j-w[i]]+v[i]); } cout << f[m] << endl; return 0;}

  

转载于:https://www.cnblogs.com/cxbky/p/4727268.html

你可能感兴趣的文章
powershell获取windows子文件夹的大小
查看>>
Html ul、dl、ol 标签
查看>>
软工读书笔记 week4 ——《黑客与画家》下
查看>>
Astyle编程语言格式化工具的说明
查看>>
java中调用javascript
查看>>
PHP数组
查看>>
C语言数据结构之单链表的拆分
查看>>
Ext属性详细信息
查看>>
codeforces A. K-Periodic Array 解题报告
查看>>
安装wamp 缺少msvcr100.dll
查看>>
light oj 1079 01背包
查看>>
bzoj2144: 跳跳棋
查看>>
设计模式学习--Singleton
查看>>
webApp开发-ionic2+angular2
查看>>
刷身份证读出相关信息
查看>>
RCC_APB2Periph_AFIO--复用IO时钟的使用
查看>>
canvas背景动画
查看>>
Spring MVC 访问静态资源
查看>>
项目部署到服务器上
查看>>
Servlet里的学问(一)
查看>>