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. H264源码分析(四)

    sub_mb_pred( mb_type ) {       for( mbPartIdx = 0; mbPartIdx < 4; mbPartIdx++ )                  ...

  2. servlet上传文件报错(一)

    1.详细报错例如以下: org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multip ...

  3. ftp 解决不能上传问题

    有人建议整个关掉SELinux并且重启,于是我去/etc/selinux/config里面把SELinux给disable了.重启之后,发现可以在/home/sam/test这个文件夹上传了!

  4. ASP.NET MVC 学习之路-4

    本文在于巩固基础 模型绑定 从URL 获取值 public ActionResult About(int id) { ViewBag.Id = id; return View(); } @{ View ...

  5. 在 PL/SQL Developer 中执行SQL文件的方法

    打开 command Window SQL> @'D:\My Documents\Downloads\bde_chk_cbo.sql'; 整个路径及文件两边要有单引号哦!

  6. EBS-利用form个性化 调用报表【Z】

    1.在工具中添加调用报表的功能 条件: 触发器事件:WHEN-NEW-FORM-INSTANCE 活动: 类型为:菜单 菜单项:specialn n为1..6 菜单标签:打印xx报表 2.对speci ...

  7. HTTP头信息(转)--1

    转自:http://www.cnblogs.com/9988/archive/2012/03/21/2409086.html 我用抓包软件抓了http的包,发现accept大多数有两种情况. 第一种: ...

  8. C++中重载、重写(覆盖)和隐藏的区别实例分析

    这篇文章主要介绍了C++中重载.重写(覆盖)和隐藏的区别,是C++面向对象程序设计非常重要的概念,需要的朋友可以参考下 本文实例讲述了C++中重载.重写(覆盖)和隐藏的区别,对于C++面向对象程序设计 ...

  9. C-JAVA 论坛

    http://www.cnblogs.com/lpjia/ JAVA黑马 http://java.itheima.com/java/service/javacourse.shtml

  10. 监控mysql执行的sql语句

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