Pick The Sticks

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

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.

 
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; typedef long long LL; const int maxn = ;
const int maxV = ; LL f[][maxV][];
int v[maxn], w[maxn];
int n, V;
void solve() {
scanf("%d%d", &n, &V); LL res = ;
for (int i = ; i < n; ++ i) {
scanf("%d%d", &v[i], &w[i]);
v[i] <<= ; res = max(res, (LL)w[i]);
}
V <<= ; int p = ; memset(f, , sizeof f);
for (int i = ; i < n; ++ i) {
p = p ^ ;
for (int j = V; j >= ; -- j) {
for (int k = ; k >= ; -- k) {
f[p][j][k] = f[p^][j][k];
if (j >= v[i]) f[p][j][k] = max(f[p][j][k], f[p^][j-v[i]][k] + w[i]);
if (k >= && j >= v[i]/) f[p][j][k] = max(f[p][j][k], f[p^][j-v[i]/][k-] + w[i]);
}
}
}
res = max(res, max(max(f[p][V][], f[p][V][]), f[p][V][]));
printf("%I64d\n", res);
} int main() {
// freopen("D.in", "r", stdin); int kase, i = ; scanf("%d", &kase);
while (kase --) {
printf("Case #%d: ", ++ i);
solve();
}
return ;
}

The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543的更多相关文章

  1. The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551

    Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  2. The 2015 China Collegiate Programming Contest E. Ba Gua Zhen hdu 5544

    Ba Gua Zhen Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  3. The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540

    Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  4. The 2015 China Collegiate Programming Contest Game Rooms

    Game Rooms Time Limit: 4000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  5. The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  6. The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550

    Game Rooms Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  7. The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547

    Sudoku Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  8. The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546

    Ancient Go Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  9. The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)

    当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...

随机推荐

  1. Mysql之复制选项与监控

    1.Slave 筛选选项: --replicate-do-db  ,同步复制哪些库 --replicate-ignore-db,忽略哪些库 --replicate-do-table=db_name.t ...

  2. mysqli的增强功能

    批量执行sql语句 批量执行dml语句 基本语法 $sqls="sql1.sql2.sql3...." mysqli::multi_query($sqls) 案例: $mysqli ...

  3. samba 最简单配置 共享

    [root@GitLab ~]# cat /etc/samba/smb.conf [global] workgroup = WORKGROUP server string = David Samba ...

  4. 苹果开发者账号申请时报错提示错误:Legal Entity Name

    he information you entered did not match your profile in the D&B database. Before submitting you ...

  5. 重温WCF之消息契约(MessageContract)(六)

    对于SOAP来说主要由两部分构成Header和Body,他们两个共同构成了SOAP的信封,通常来说Body保存具体的数据内容,Header保存一些上下文信息或关键信息.比如:在一些情况下,具有这样的要 ...

  6. Delphi面向对象编程

    一.面向对象介绍 OOP是使用独立的对象(包含数据和代码)作为应用程序模块的范例.虽然OOP不能使得代码容易编写,但是它能够使得代码易于维护.将数据和代码结合在一起,能够使定位和修复错误的工作简单化, ...

  7. c++ 子类调用父类构造方法 调用父类方法 类声明与实现分离

    Person.h #pragma once #include "stdafx.h" #include<iostream> class Person { private: ...

  8. JavaScript获取当前根目录

    JavaScript获取当前根目录 主要用到Location 对象,包含有关当前 URL 的信息,是 Window 对象的一个部分,可通过 window.location 属性来访问. 方法一 (wi ...

  9. 限制非安全IP访问

    这个是一个检测ip是否非法的php函数,适应于白名单,黑名单功能开发,主要场景应用于:api来源限制,访问限制等. /** * 安全IP检测,支持IP段检测 * @param string $ip 要 ...

  10. hdu 4039 2011成都赛区网络赛I ***

    两层搜索,直接for循环就行了,还要注意不能是自己的朋友 #include<cstdio> #include<iostream> #include<algorithm&g ...