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

因此加一维即可,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. 《HTML5与CSS3权威指南》读书笔记(上册)—HTML5篇

    豆瓣上的评分少且评价不太好,阅读当中发现几处刊物上的小问题,不过线下口碑貌似不错,基本上人手一本 上册五百多页,主讲H5,分为标签,本地存储,离线应用程序,新的API,获取地理位置信息标签包含表单,C ...

  2. cetos6 安装samba共享文件夹

    yum方式安装 yum install samba 修改配置文件 vim /etc/samba/smb.conf [global] comment = global workgroup = QFpay ...

  3. myeclipse连接数据库oracle(添加jdbc.properties)

    第一步:在src下面建一个包com.xsl.conf 第二步:在建好的包下面新建一个jdbc.properties 第三步:在jdbc.properties里写入内容如下: driver = orac ...

  4. namenode无法启动

    查看日志错误信息关键语句: There appears to be a gap in the edit log.  We expected txid 44353, but got txid 原因: n ...

  5. SEO定义目的,优化的好处

    SEO:search engine optimization(搜索引擎优化) SEO严谨的定义:SEO是指在了解搜索引擎自然排名机制的基础上,对网站进行内部及外部的调整优化,改进网站在搜索引擎中关键字 ...

  6. 教务处sso设计缺陷

    前言 刚学习python,觉得比较枯燥总不知道从哪里入手,偶然一次,同学让我帮忙看看选课,发给我的是学校统一的默认格式的密码,突然就想试试有多少人还是默认密码,从QQ群里找了一份学生信息尝试了一下,发 ...

  7. maven 阿里镜像

    <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>al ...

  8. 在家用机上搭建 Git https 服务器

    今天主要叙述在家里台式机的虚拟机上搭建支持 https 的 ubuntu git 服务器. 实际上,从一个用户请求家里 git 服务器代码,最终完成代码的传输,主要是通过以下的过程: 首先,从外界寻找 ...

  9. Spring Security(07)——缓存UserDetails

    Spring Security提供了一个实现了可以缓存UserDetails的UserDetailsService实现类,CachingUserDetailsService.该类的构造接收一个用于真正 ...

  10. 通过this获取当前点击选项相关数据

    很多时候jquery只能或者应该回去一个集合.然后通过this获取触发时间的对象及相关属性 this.jq('#needsType').on("click", ".sel ...