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. Data Structure(3)——软考阶段学习小结

    数据结构计算机等级考试中有,自考中有,软考中同样有,可见其内容的重要程度,今天对软考阶段视频学习内容的总结,同样是对前面学习内容的回顾,同样是对后面学习的铺垫. 中结:原本因为之前有过类似的总结,这次 ...

  2. oauth2认证

    using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Con ...

  3. 用程序对hdfs进行操作。

    调试加安装了半天,怎么也没有配置好怎么通过Eclipse直接连接hdfs,最后我还是打成一个jar包放到Linux虚拟机中运行的. 运行命令Java -jar  XXX.jar. 当中对hdfs的操作 ...

  4. NodeJS下载文件实例

    var http = require('http');var express = require('express');var fs=require("fs"); var app ...

  5. PHP获取中文汉字首字母方法

    function getFirstLetter($str){ $fchar = ord($str{0}); if($fchar >= ord("A") and $fchar ...

  6. 出现"无法连接synaptics定点装置驱动程序"

    "开始“--”运行“--regedit(打开注册表)--依次打开 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVERSION/R ...

  7. e3.tree参考手册

    简介 1. E3.Tree是E3平台下一个用于构造树型UI(menu,tree,outlookbar等)的的组件, E3.Tree 特色  部署简单,只需要把相关jar放到WEB-INF/lib目录 ...

  8. 关于webapp中的文字单位的一些捣腾

    前言 文字是网页内容的一枚大将,我们无时无刻都在看着它,只要是你盯屏幕上的任何一个地方都会有文字.地铁上无时无刻都在盯着屏幕上的人对于文字更为敏感,太大不行,太小TN又看不清上面到底在说什么,有时候车 ...

  9. 深入理解this对象

    最近一直在看js关于面向对象编程方面的东西,那么this肯定是需要一个被吃透 理解 同时灵活运用的对象 现在总结一下自己的学习成果: 我们可以用一句很形象的话来理解什么是this关键字? " ...

  10. Cmd批处理语法实例

    @echo on :循环获取指定目录下以php为后缀的文件,且重命名后缀为html :for /r "E:\aaa\web" %%v in (*.php) do ren " ...