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. 兔子--Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

    错误原因: Activity打开别的Activity的时候会默认把新的Activity放到自己的task中,所以不用指定,可是别的地方就得指定了. 解决的方法:intent.addFlags(Inte ...

  2. 一台服务器同时搭建IIS和WAMP,利用WAMP 80端口转发

    打开wamp 里面的 httpd.conf 文件,找到以下四个语句,取消注释 #LoadModule proxy_module modules/mod_proxy.so -->LoadModul ...

  3. javascript高级知识分析——实例化

    代码信息来自于http://ejohn.org/apps/learn/. new做了什么? function Ninja(){ this.name = "Ninja"; } var ...

  4. ASP.NET递归添加树节点

    表设计如图: id        title         parentid 1         asp.net   0 2         c#           0 3         c#_ ...

  5. win7 64位系统调试zkemkeeper.dll出错误解决

    最近调用中控科技dll文件总是会出现上问题,网上找了大半天都没解决? 今天终于解决,原来是旧的dll文件是有问题,在中控网站上下载了最新的sdk(64位),解压,找到sdk的全部文件夹. 全选所有的: ...

  6. Android studio 查看sha1

    高德地图开发申请KEY的时候需要开发者提供SHA1证书指纹数据,在eclipse很容易就找到了,但是Android Studio很久也没找到,只能使用在网上看到的方法了,在Android Studio ...

  7. 转载:NSobject官方介绍

    概述: NSObject协议组对所有的Object-C下的objects都生效. 如果objects遵从该协议,就会被看作是first-class objects(一级类). 另外,遵从该协议的obj ...

  8. MYSQL 错误日志

    背景知识 : 就算我们不配置mysql的错误文件,它也会有一个默认的,在data文件夹下保存(.err文件) 还好这个文件保存在哪我们还是可以配置的 配置方法: log-err=E:\DB\mysql ...

  9. 15.java.lang.InstantiationException

    java.lang.InstantiationException 实例化异常 当试图通过Class的newInstance()方法创建某个类的实例,但程序无法通过该构造器来创建该对象时引发 Class ...

  10. 对web应用中单一入口模式的理解及php实现

    在我们web应用的开发中,经常会听见或看见单一入口模式,在我开始学习tp框架的时候也不理解为什么要运用一个单一入口模式,只是会使用,最近自己在搞一个小东西的时候才明白为什么在web开发中要运用单一入口 ...