Pick The Sticks

Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 2398    Accepted Submission(s): 785

Problem Description

The story happened long long ago. One day, Cao Cao made a special order called "Chicken Rib" to his army. No one got his point and all became very panic. However, Cao Cao himself felt very proud of his interesting idea and enjoyed it.

Xiu Yang, one of the cleverest counselors of Cao Cao, understood the command Rather than keep it to himself, he told the point to the whole army. Cao Cao got very angry at his cleverness and would like to punish Xiu Yang. But how can you punish someone because he's clever? By looking at the chicken rib, he finally got a new idea to punish Xiu Yang.

He told Xiu Yang that as his reward of encrypting the special order, he could take as many gold sticks as possible from his desk. But he could only use one stick as the container.

Formally, we can treat the container stick as an L length segment. And the gold sticks as segments too. There were many gold sticks with different length ai and value vi. Xiu Yang needed to put these gold segments onto the container segment. No gold segment was allowed to be overlapped. Luckily, Xiu Yang came up with a good idea. On the two sides of the container, he could make part of the gold sticks outside the container as long as the center of the gravity of each gold stick was still within the container. This could help him get more valuable gold sticks.

As a result, Xiu Yang took too many gold sticks which made Cao Cao much more angry. Cao Cao killed Xiu Yang before he made himself home. So no one knows how many gold sticks Xiu Yang made it in the container.

Can you help solve the mystery by finding out what's the maximum value of the gold sticks Xiu Yang could have taken?

 

Input

The first line of the input gives the number of test cases, T(1≤T≤100). T test cases follow. Each test case start with two integers, N(1≤N≤1000) and L(1≤L≤2000), represents the number of gold sticks and the length of the container stick. N lines follow. Each line consist of two integers, ai(1≤ai≤2000)and vi(1≤vi≤109), represents the length and the value of the ith gold stick.
 

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum value of the gold sticks Xiu Yang could have taken.
 

Sample Input

4

3 7
4 1
2 1
8 1

3 7
4 2
2 1
8 4

3 5
4 1
2 2
8 9

1 1
10 3

 

Sample Output

Case #1: 2
Case #2: 6
Case #3: 11
Case #4: 3

Hint

In the third case, assume the container is lay on x-axis from 0 to 5. Xiu Yang could put the second gold stick center at 0 and put the third gold stick center at 5,
so none of them will drop and he can get total 2+9=11 value.

In the fourth case, Xiu Yang could just put the only gold stick center on any position of [0,1], and he can get the value of 3.

 

Source

 
 //2017-10-08
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
const int L = ;
int n, l, w[N];
long long dp[L][], v[N];//dp[j][k]表示容量为j的背包,有k个物品重量折半放入时的最大价值。 int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &l);
l *= ;//为防止出现浮点数,总容量和每个物品的重量都乘2。
long long ans = ;
for(int i = ; i <= n; i++){
scanf("%d%lld", &w[i], &v[i]);
w[i] *= ;
ans = max(ans, v[i]);//只取一个物品时,无论重量为多少都可以取。
}
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++){
for(int j = l; j >= w[i]/; j--){
for(int k = ; k <= ; k++){
if(j >= w[i])dp[j][k] = max(dp[j][k], dp[j-w[i]][k]+v[i]);
if(k && j >= w[i]/)dp[j][k] = max(dp[j][k], dp[j-w[i]/][k-]+v[i]);
}
}
}
for(int k = ; k <= ; k++)
ans = max(ans, dp[l][k]);
printf("Case #%d: %lld\n", ++kase, ans);
} return ;
}

HDU5543(SummerTrainingDay03-O DP)的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. ASP.NET WebApi JObject 使用

    ASP.NET WebApi 中使用非Get请求,传递参数需要用对象包裹起来,比如: [HttpPost] public async Task<IActionResult> PostVal ...

  2. Codeforces gym102152 K.Subarrays OR

    传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...

  3. 分布式任务调度系统xxl-job源码探究(一、客户端)

    前面讲了xxl-job的搭建,现在来粗略的解析下该分布式调度系统的源码,先来客户点代码 客户端源码 客户端开启的时候会向服务中心进行注册,其实现用的是jetty连接,且每隔半分钟会发送一次心跳,来告诉 ...

  4. Tools - Atom编辑器

    Atom官网 Atom编辑器的常用插件 预览 document-outline:Show a heirarchical outline of a text document minimap:A pre ...

  5. Tools - Vim

    Vim 简明 Vim 练级攻略 基础设置 在vim界面点击":"然后进行设置,但只会在当前vim界面生效: 添加相关设置在vim配置文件(例如"/etc/vimrc&qu ...

  6. java调用高德地图api实现通过ip定位访问者的城市

    所需东西:高德地图的key 注意:这个key是 web服务的key  和js的key不是一个key(若没有则自行创建,创建教程在文末) 高德地图的api文档:https://lbs.amap.com/ ...

  7. git无法识别新增的文件

    问题是这样的我新增几个文件夹打算提交到git库,但输入指令:“git status” 发现新增的文件夹并没有出现在准备提交区里 不知道什么原因造成的后来我百度找到方法 使用指令:“git add -f ...

  8. Xamarin.Android 记住账号

    1.存储登陆信息 if(login_cb_user.Checked) { ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPr ...

  9. Android 系统内核层与 Linux Kernel 的比较

    Android 内核具有和标准 Linux 内核一样的功能,主要实现了内存管理.进程调度.进程间通信等功能.但在文件系统.进程间通信.内存管理等方面存在差异. 1.文件系统.移动设备采用的大多不是硬盘 ...

  10. MariaDB 数据库

    1. MariaDB 介绍 MariaDB数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成 ...