Bone Collector II

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4229    Accepted Submission(s): 2205

Problem Description
The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't matter,I will give you a link:

Here is the link:http://acm.hdu.edu.cn/showproblem.php?pid=2602

Today we are not desiring the maximum value of bones,but the K-th maximum value of the bones.NOTICE that,we considerate two ways that get the same value of bones are the same.That means,it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.

If the total number of different values is less than K,just ouput 0.

 
Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, K(N <= 100 , V <= 1000 , K <= 30)representing the number of bones and the volume of his bag and the K we need. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.
 
Output
One integer per line representing the K-th maximum of the total value (this number will be less than 231).
 

Sample Input

3
5 10 2
1 2 3 4 5
5 4 3 2 1
5 10 12
1 2 3 4 5
5 4 3 2 1
5 10 16
1 2 3 4 5
5 4 3 2 1
 
Sample Output
12
2
0
 
Author
teddy

每个状态保存1到k优值,转移时给f[j][]和f[j-v][]+w二路归并一下就好了
复杂度O(nvk)
注意本题是严格递减
 
//
// main.cpp
// hdu2639
//
// Created by Candy on 9/22/16.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,V=,K=,INF=1e9+;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int T,n,m,k,w[N],v[N];
int f[V][K],a[K],b[K];
void dp(){
memset(f,,sizeof(f));
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<=n;i++)
for(int j=m;j>=v[i];j--){
for(int z=;z<=k;z++) {a[z]=f[j][z];b[z]=f[j-v[i]][z]+w[i];}
int x=,y=,z=;
while(z<=k&&(x<=k||y<=k)){
if(a[x]>=b[y]) f[j][z]=a[x++];
else f[j][z]=b[y++];
if(f[j][z]!=f[j][z-]) z++;
}
}
}
int main(int argc, const char * argv[]) {
T=read();
while(T--){
n=read();m=read();k=read();
for(int i=;i<=n;i++) w[i]=read();
for(int i=;i<=n;i++) v[i]=read();
dp();
printf("%d\n",f[m][k]);
} return ;
}

HDU2639Bone Collector II[01背包第k优值]的更多相关文章

  1. HDU - 2639 Bone Collector II (01背包第k大解)

    分析 \(dp[i][j][k]\)为枚举到前i个物品,容量为j的第k大解.则每一次状态转移都要对所有解进行排序选取前第k大的解.用两个数组\(vz1[],vz2[]\)分别记录所有的选择情况,并选择 ...

  2. HDU 2639 (01背包第k优解)

    /* 01背包第k优解问题 f[i][j][k] 前i个物品体积为j的第k优解 对于每次的ij状态 记下之前的两种状态 i-1 j-w[i] (选i) i-1 j (不选i) 分别k个 然后归并排序并 ...

  3. HDU 3639 Bone Collector II(01背包第K优解)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. (01背包 第k优解) Bone Collector II(hdu 2639)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639       Problem Description The title of this problem i ...

  5. 杭电 2639 Bone Collector II【01背包第k优解】

    解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...

  6. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. HDU 2639 Bone Collector II (01背包,第k解)

    题意: 数据是常规的01背包,但是求的不是最大容量限制下的最佳解,而是第k佳解. 思路: 有两种解法: 1)网上普遍用的O(V*K*N). 2)先用常规01背包的方法求出背包容量限制下能装的最大价值m ...

  8. hdu–2369 Bone Collector II(01背包变形题)

    题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...

  9. HDU 2639 Bone Collector II(01背包变型)

    此题就是在01背包问题的基础上求所能获得的第K大的价值. 详细做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,事实上就 ...

随机推荐

  1. Slides - 在线制作效果精美的幻灯片(PPT)

    Slides 是可以在浏览器中使用的在线幻灯片编辑器.与传统的演示软件,比如 PowerPoint 相比,Slides 不需要下载任何东西.你所有的信息都是安全地存储在我们的服务器上,无论你在哪里.不 ...

  2. 简单代码在ABAP中实现声音的播放

    这段代码的功能是在SAP里面实现声音的播放,可以用作程序提醒功能,和SAP里面’噹噹噹’那个声音的意思差不多.将来在项目中遇到客户想要SAP ABAP发出一点声音的时候就可以参考一下这个程序. REP ...

  3. Core Animation - 核心动画

    CAAnimation类,是一个抽象类.遵循CAMediaTiming协议和CAAction协议! CAMediaTiming协议 可以调整时间,包括持续时间,速度,重复次数. CAAction协议  ...

  4. struts理解

    最近大家都在找工作,我好迷茫,觉得自己会的东西太少了.所以决定开始学习SSH三大框架. 首先是struts. struts是基于mvc模式的框架.(struts其实也是servlet封装,提高开发效率 ...

  5. YTKNetworkConfig配置HTTPS请求

    YTKNetworkConfig配置HTTPS请求 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ad91cc ...

  6. Markdown语法手册

    Markdown 语法手册 Markdown 是一种轻量级标记语言,能将文本换成有效的XHTML(或者HTML)文档,它的目标是实现易读易写,成为一种适用于网络的书写语言. Markdown 语法简洁 ...

  7. 网络编程--ASI--(ASIHTTPRequest)介绍

    ASIHTTPRequest 虽然是明日黄花,但是还是稍微归纳一下,理清思路,知道这个曾经的她都能干嘛. 1. ASI基于底层的 CFNetworking 框架,运行效率很高. 2. 黄金搭档:ASI ...

  8. 学习Coding-iOS开源项目日志(三)

    继续前两篇,接着本第三篇<学习Coding-iOS开源项目日志(三)>讲解Coding-iOS开源项目. 前 言:作为初级程序员,想要提高自己的水平,其中一个有效的学习方法就是学习别人好的 ...

  9. MySQL主主双机负载均衡

    MySQL双机主主架构,其上辅以负载均衡设备,可以实现mysql数据库的负载均衡高性能和高可用性,负载均衡设备可以根据算法将数据库操作的负 载平均分到两台MySQL服务器上,这样对于每台服务器来说工作 ...

  10. DevExpress ASPxSplitter ClientSideEvents-PaneExpanded 时间用法

    在webform中的devexpress aspxsplitter中套用了jquery-easyui的 tabs id=tt <div id="tt" class=" ...