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