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

  1. 4 6
  2. 1 4
  3. 2 6
  4. 3 12
  5. 2 7

Sample Output

  1. 23
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cmath>
  4. #define max1 13880
  5. using namespace std;
  6. int main()
  7. {
  8. 	int n,c;
  9. 	while(cin>>n>>c)
  10. 	{
  11. 		int m[max1]={0};
  12. 		int w[max1];
  13. 		int v[max1];
  14. 		for(int i=1;i<=n;i++)
  15. 		  cin>>w[i]>>v[i];
  16.         for(int i=1;i<=n;i++)
  17.            for(int j=c;j>=w[i];j--)
  18.               m[j]=max(m[j],m[j-w[i]]+v[i]);
  19.         cout<<m[c]<<endl;
  20. 	}
  21. 	return 0;
  22. }
  23.  

随机推荐

  1. 纯CSS3实现自定义涂鸦风格的边框

    今天我们要来分享一款基于纯CSS3的自定义边框应用,看上去它像一个Tooltip控件,因为下边框有一个小三角,就像很多地方的引用文本框一样.另外这款CSS3边框是涂鸦风格的,看起来很有个性.用CSS3 ...

  2. Row versus Set Processing, Surprise!(集合处理和单行处理数据的差异性)

    Row versus Set Processing, Surprise! Craig Shallahamer: 1. Set based processing will likely be much ...

  3. light oj 1027 A Dangerous Maze

    一道数学期望题,唉唉,概率论学的不好啊~~ 求走出迷宫的期望时间. 由于有的门会回到起点,所以有可能会走很多遍,设能走出去的门的个数为n1,总的个数为n,那么一次走出去的概率为n1/n,走一次的用的平 ...

  4. 监控mysql执行的sql语句

    linux平台 监控mysql执行的sql语句   为了做好配合开发做性能和功能测试,方便监控正在执行的sql语句, 可以在/etc/mysqld中添加如下:  log =/usr/local/mys ...

  5. PICT安装及使用

    一:PICT安装 1.下载pict33.msi:http://vdisk.weibo.com/s/d6k2tcgXDa7Eq 2.安装: 二:PICT的使用 1.在F:\PICT 目录下,新建一个tx ...

  6. [原创]使用GCC创建 Windows NT 下的内核DLL

    原文链接:使用GCC创建 Windows NT 下的内核DLL 在温习<<Windows 2000 Driving>>分层驱动程序一章的时候,看到了关于紧耦合驱动连接方式,这种 ...

  7. CSS自学笔记(6):CSS的模型

    CSS 框模型 (Box Model) 规定了元素框处理元素内容.内边距.边框和外边距的方式. 图片来源:w3school.com.cn 元素(element)是一个html文档的实际内容区域,依次由 ...

  8. ELMAH+MVC4+SQLite 错误日志

    任何程序我想无论是在调试开发阶段还是上线运营阶段,都能够使人“放心”,不要出什么意外,也不要玩什么心跳:那就需要比较到位和及时的异常与错误日志模块. 本文将简要描述ELMAH.MVC4与SQLite这 ...

  9. alois

    Background It's not simple to know what happens in a bigger network. There's a multitude of applicat ...

  10. FIDO联盟:我们将杀死密码

    前不久发布的三星S5与iPhone 5S一样,配备了指纹识别技术.但更为重要的是,这一识别器可以与PayPal关连,进而与多种支付系统相连.通过这一过程,你很可能会摆脱密码,用指纹就可以畅游网络.当然 ...