Charm Bracelet

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 38909   Accepted: 16862

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

题目链接:http://poj.org/problem?id=3624
分析:01背包裸题,顺带敲了一遍,做个复习吧,怕忘了!详解请参看我的博客http://www.cnblogs.com/ECJTUACM-873284962/p/6815610.html,里面有对01背包的完全介绍以及用法!
下面给出AC代码:
 #include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int w[],d[],dp[];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&d[i]);
for(int i=;i<=n;i++)
{
for(int j=m;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]+d[i]);
}
}
printf("%d\n",dp[m]);
}
return ;
}

最新文章

  1. DIOCP之DEMO-Echo卡死问题分析
  2. android免root兼容所有版本ui调试工具
  3. PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
  4. Linux Free命令各数字含义及Buffer和Cache的区别
  5. Linq to Entities下存储过程的使用方法
  6. tp框架表单验证
  7. Dynamics AX 2012 R2 在报表上显示和打印条码
  8. ProcessOn:功能强大的在线作图工具(HTML5)
  9. 《linux程序设计》--读书笔记--第十四章信号量、共享内存和消息队列
  10. myisam和innodb区别
  11. HTML 颜色名
  12. JMeter接口测试系列-关联参数
  13. 必须要会的 50 个 React 面试题
  14. [JSOI2009]等差数列
  15. 转 lightmap
  16. [转]MySQL源码:Range和Ref优化的成本评估
  17. C++ Enum 转 Lua Table工具
  18. Dockerfile 指令汇总及解析
  19. ActiveMQ队列特性:删除不活动的队列(Delete Inactive Destinations)
  20. ava中有三种移位运算符

热门文章

  1. 【python】字符串
  2. iOS UITabView简写瀑布流
  3. 面试题汇总--数据储存/应用程序/UI控件/客户端的安全性与框架处理。。。
  4. 函数PYXX_READ_PAYROLL_RESULT的dump问题
  5. HTML干货
  6. 用keras作CNN卷积网络书本分类(书本、非书本)
  7. iptables 命令详解
  8. 【Python3之字符编码】
  9. SQL Server 审计操作概念
  10. 我的Python学习笔记(四):动态添加属性和方法