A - A

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d
& %I64u

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;
}

随机推荐

  1. js生成随机数的方法实例总结 [收藏]

    js生成随机数的方法实例总结 js生成随机数主要用到了内置的Math对象的random()方法.用法如:Math.random().它返回的是一个 0 ~ 1 之间的随机数.有了这么一个方法,那生成任 ...

  2. SecureCRT 绝佳配色方案, 保护你的眼睛(转发)

    SecureCRT 绝佳配色方案, 保护你的眼睛 关键词:SecureCRT配色, SecureCRT设置颜色, Linux终端配色,Linux终端颜色设置. 终端有一个好的配色,不仅能保护自己的眼睛 ...

  3. Response.Redirec方法传递汉字出现乱码

    解决方法: //传参数时Response.Redirect("a.aspx?name"+Server.UrlEncode("我的名字")); //接收参数时 S ...

  4. create a (VSTO) Office 2007 add-in using VS 2012?

    You can get VS 2012 working with Office 2007. First create an Outlook 2010 Add-In and modify the pro ...

  5. node.js常见错误及解决办法

    1.npm express命令行下不能执行 解决办法: 4版本需要安装express-generatorc才能使用express命令npm install -g express-generatorwh ...

  6. C# DataTable 详解

    添加引用 using System.Data; 创建表 //创建一个空表 DataTable dt = new DataTable(); //创建一个名为"Table_New"的空 ...

  7. OCI_INVALID_HANDLE 什么原因

    查看oci.dll应用版本和服务器版本是否一致

  8. Mongodb基础知识----Mongodb权威指南阅读

    文档是Mongodb中数据的基本单元,类型关系型数据库中的行,每个文档都有一个键值唯一的键_id.集合可以看做拥有动态模式的表. Mongodb一个实例可以拥有多个相互独立的数据库. Mongodb区 ...

  9. python 杨辉三角 算法实现

    def triangles(level): n = 1 L = [] while n <=level: if n <= 2: L.append(1) yield L elif n > ...

  10. 21个值得收藏的Javascript技巧

    1  Javascript数组转换为CSV格式 首先考虑如下的应用场景,有一个Javscript的字符型(或者数值型)数组,现在需要转换为以逗号分割的CSV格式文件.则我们可以使用如下的小技巧,代码如 ...