A - A
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
#include<iostream>
#include<algorithm>
#include<cmath>
#define max1 13880
using namespace std; int main()
{
int n,c;
while(cin>>n>>c)
{
int m[max1]={0};
int w[max1];
int v[max1];
for(int i=1;i<=n;i++)
cin>>w[i]>>v[i];
for(int i=1;i<=n;i++)
for(int j=c;j>=w[i];j--)
m[j]=max(m[j],m[j-w[i]]+v[i]); cout<<m[c]<<endl;
} return 0;
}
随机推荐
- SQL2012尝试读取或写入受保护的内存。这通常指示其他内存已损坏
SQL2012尝试读取或写入受保护的内存.这通常指示其他内存已损坏 今天打开SQL2012,突然就连接不了数据库,一开始还以为是某个服务器崩溃了,结果试了好几个,都还是如此,弹出提示如下: 尝试读取或 ...
- 在 IIS 中配置 ASP.NET 应用程序
注意事项: 1.注册.NET 如果先安装.net平台,后安装IIS,那么在IIS中可能就没有出现ASP.NET版本的下拉菜单,就要手动注册: 一般.Net版本都存放在:C:\WINDOWS\Micr ...
- Csharp实现快速排序
public void QuickSort(int[] arr, int left, int right) //快速排序 { //先从数列中去处一个数作为基准数 //分区过程,将比这个数大的数全放在他 ...
- 并发编程: c++11 thread(Func, Args...)利用类成员函数创建线程
c++11是VS2012后支持的新标准,为并发编程提供了方便的std::thread. 使用示例: #include <thread> void thread_func(int arg1, ...
- [C++]unordered_map的使用
unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value. 不同的是unordered_map不会根据key的大小进行排序,存储时是根据key的ha ...
- Constructor JavaScript构造器模式。
构造器模式 : Constructor模式中, 通过在构造器前面加 new 关键字, 告诉JavaScript 像使用构造器一样实例化一个新对象,并且对象成员由该函数定义. 构造器内, 使用this ...
- python 杨辉三角 算法实现
def triangles(level): n = 1 L = [] while n <=level: if n <= 2: L.append(1) yield L elif n > ...
- python打包成.exe工具py2exe0-----No such file or directory错误
转自:http://justcoding.iteye.com/blog/900993 一.简介 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具, ...
- 【转】MUD教程--巫师入门教程1
<新巫师入门手册> 第一章:观念篇■ 内容提要:什么是巫师?怎样做一个巫师?如何做好一个巫师? 第二章:上手篇■ 内容提要:最简单的房间怎么写?NPC又怎么写?先看懂一些常用的参数? 第三 ...
- 51cto那些技术专题们
Nginx配置与应用详解 UML(Unified Modeling Language,统一建模语言) 架构师的成长历程 python python book ruby html5 不可不知的Linux ...