背包变形。与普通的背包问题不同的是:允许有两个物品可以花费减半。

因此加一维即可,dp[i][j][k]表示前i个物品,有j个花费减半了,总花费为k的情况下的最优解。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} int T,n,L;
LL f[][][];
struct X{int a;LL v;}s[]; int main()
{
scanf("%d",&T); int cas=; while(T--)
{
scanf("%d%d",&n,&L); L=L*; LL ans=;
for(int i=;i<=n;i++)
{
scanf("%d%lld",&s[i].a,&s[i].v);
s[i].a=s[i].a*;
ans=max(ans,s[i].v);
}
memset(f,,sizeof f); int p=;
for(int i=;i<=n;i++)
{
p=p^;
for(int j=;j<=;j++)
{
for(int c=;c<=L;c++)
{
f[p][j][c]=f[p^][j][c];
if(c-s[i].a>=) f[p][j][c]=max(f[p][j][c],f[p^][j][c-s[i].a]+s[i].v);
if(j->=&&c-s[i].a/>=) f[p][j][c]=max(f[p][j][c],f[p^][j-][c-s[i].a/]+s[i].v);
ans=max(ans,f[p][j][c]);
}
}
}
printf("Case #%d: %lld\n",cas++,ans);
}
return ;
}

HDU 5543 Pick The Sticks的更多相关文章

  1. hdu 5543 Pick The Sticks(动态规划)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:给你一根长为m的长木板和一些小木棒,每一根小木棒有它的长度和价值,这些小木棒要放在长木板上 ...

  2. HDU 5543 Pick The Sticks:01背包变种

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意: 给你N个金条和一张长度为L的桌子.每个金条长度为a[i],价值为w[i].金条只能在桌子 ...

  3. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  4. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  5. CDOJ 1218 Pick The Sticks

    Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  6. 2015南阳CCPC D - Pick The Sticks 背包DP.

    D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...

  7. [HDOJ5543]Pick The Sticks(DP,01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意:往长为L的线段上覆盖线段,要求:要么这些线段都在L的线段上,要么有不超过自身长度一半的部分 ...

  8. HDOJ5543 Pick The Sticks

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题目大意:有n个金条,每个金条有长度和价值,给一个长度为L的容器,当金条在容器两端的时候,只要重 ...

  9. HDU 1051:Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. juit测试中报错:org.hibernate.HibernateException: Unable to get the default Bean Validation factory

    org.hibernate.HibernateException: Unable to get the default Bean Validation factory 解决方法: 解决方案: 在hib ...

  2. wefwewewe

    <a hred="https://www.baidu.com">dssf</a>

  3. Centos安装vncserver服务

    vnc是一款Windows远程桌面软件,其优点是支持跨操作系统的远程图形化控制.下面开始记录第一次安装vnc服务的过程. 1.先检查系统是否有安装VNC服务 [root@localhost ~]# [ ...

  4. 闭包&装饰器详解

    闭包 先不着急看闭包的定义,让我们从一段示例代码开始.如果将上一个示例稍微修改下: >>> def outer(): ... x = 1 ... def inner(): ... p ...

  5. Tomcat下log4j设置文件路径和temp目录

    转自:http://www.cnblogs.com/dkblog/archive/2007/07/27/1980873.html 在Web应用中的如何设置日志文件的路径呢?最笨的方法是写绝对路径,但很 ...

  6. POJ 2656 Unhappy Jinjin

    #include <stdio.h> int main() { ) { int i, n; ; scanf("%d", &n); ) break; ; i &l ...

  7. hdu1012

    #include<iostream>#include<stdio.h> using namespace std; int jiechen(int n){    int i;   ...

  8. 第五十三节,socket模块介绍,socket单线程通讯

    socket单线程通讯,只能单线程通讯,不能并发 socket是基于(TCP.UDP.IP)的通讯.也叫做套接字 通讯过程由服务端的socket处理信息发送,由客户端的socket处理信息接收. so ...

  9. HDU3791二叉搜索树(二叉树)

    Problem Description 判断两序列是否为同一二叉搜索树序列   Input 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束.接下去一行是一 ...

  10. Flask-Request对象属性

    Request属性 元属性 method host path environ headers data body中的内容 最安全 解析后 remote_addr args form values  a ...