博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3624 01背包模板题
阅读量:4207 次
发布时间:2019-05-26

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

Charm Bracelet
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 41414   Accepted: 17991

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

Sample Output

23

Source

[]   [Go Back]   []   []

const int maxn=3500;const int maxm=13000;int n,m;int dp[maxm];int w[maxn],v[maxn];int main(){    while(cin>>n>>m)    {        memset(dp,0,sizeof(dp));        memset(w,0,sizeof(w));        memset(v,0,sizeof(v));        for(int i=1;i<=n;i++)cin>>w[i]>>v[i];        for(int i=1;i<=n;i++)            for(int j=m;j>=w[i];j--)                dp[j]=max(dp[j],dp[j-w[i]]+v[i]);        cout<
<

转载地址:http://ceali.baihongyu.com/

你可能感兴趣的文章
python与正则表达式
查看>>
安装.Net Framework 4.7.2时出现“不受信任提供程序信任的根证书中终止”的解决方法
查看>>
input type=“button“与input type=“submit“的区别
查看>>
解决Github代码下载慢问题!
查看>>
1.idea中Maven创建项目及2.对idea中生命周期的理解3.pom文件夹下groupId、artifactId含义
查看>>
LeetCode-栈|双指针-42. 接雨水
查看>>
stdin,stdout,stderr详解
查看>>
Linux文件和设备编程
查看>>
文件描述符
查看>>
终端驱动程序:几个简单例子
查看>>
登录linux密码验证很慢的解决办法
查看>>
fcntl函数总结
查看>>
HTML条件注释
查看>>
Putty远程服务器的SSH经验
查看>>
内核态与用户态
查看>>
使用mingw(fedora)移植virt-viewer
查看>>
趣链 BitXHub跨链平台 (4)跨链网关“初介绍”
查看>>
C++ 字符串string操作
查看>>
MySQL必知必会 -- 了解SQL和MySQL
查看>>
MySQL必知必会 -- 使用MySQL
查看>>