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. asp-net-web-api 自定义URl插件

    http://attributerouting.net/#asp-net-web-api https://github.com/johnpapa/CodeCamper/blob/master/Code ...

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

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

  3. 在spring中进行基于Executor的任务调度

    Executor java.util.concurrent.Executor接口的主要目的是要将“任务提交”和“任务执行”两者分离解耦.该接口定义了任务提交的方法,实现者可以提供不同的任务运行机制,解 ...

  4. QF——OC的多态,动态绑定及实现原理

    多态: 封装,继承,多态是面向对象的三大特征. 那多态到底是什么呢? 多态:允许不同的类定义相同的方法,OC能自己判断当前类所对应的方法,不会混乱. 动态类型:程序直到运行时才确定对象的类型. 动态绑 ...

  5. css3 drop-shaow阴影效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  6. PHP EOF(heredoc)的使用

    <?php /* Heredoc技术,在PHP手册和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术. 目前一些论坛程序和CMS系统使用了这种技术,前不久看一个朋友的P ...

  7. codeforces 8D Two Friends 二分+ 判断三个圆是否有公共交点

    题目链接 有两个人x, y, 现在在A点, x要直接去B点, y要先去C点在去B点, 现在给出x, y两人可以行走的最大距离T1, T2, 求出他们从A点出发之后, 可以走的最长的公共路径. 我们先看 ...

  8. C#BASE64 UTF8字符串加密解密

    base 64 解码 base64 bb = new base64(); string orgStr= Encoding.Default.GetString(bb.GetDecoded("b ...

  9. mini-httpd源码分析-tdate_parse.h

    ///关联字符串和整数 struct strlong { char* s; long l; }; ///将字符串中的大写字母转换成小写字母 static void pound_case(char* s ...

  10. 程序员眼里IE浏览器是什么样的

    主流浏览器之争从上个世纪开就开始,已经持续了很长的时间.就在几年前,IE还是最主流的web浏览器.但现在形势完全不同了,人们都在笑话IE,纷纷转向其它浏览器.今天,我向大家分享一下针对IE的搞笑图片, ...