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 2 31). 
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
题目大意:
输入n,v,k分别代表n个物品,v的体积,以及要求v能装下第k大的价值。
01背包变形,加一维代表第几大,最后dp[v][k]即为答案。
#include <iostream>
#include <cstring>
using namespace std;
int v[],w[];
int dp[][],a[],b[];
int n,val,k;
int main()
{
int T;
cin>>T;
while(T--)
{
memset(dp,,sizeof dp);
cin>>n>>val>>k;
for(int i=;i<=n;i++)
cin>>v[i];
for(int i=;i<=n;i++)
cin>>w[i];
for(int i=;i<=n;i++)
for(int j=val;j>=w[i];j--)
{
for(int l=;l<=k;l++)
{
a[l]=dp[j][l];///不取
b[l]=dp[j-w[i]][l]+v[i];//取
}
a[k+]=b[k+]=-;
int x=,y=,z=;
while(z<=k&&(x<=k||y<=k))///更新,也可以直接排序
{
if(a[x]>b[y])
dp[j][z]=a[x++];
else
dp[j][z]=b[y++];
if(dp[j][z]!=dp[j][z-])
z++;
}
}
cout<<dp[val][k]<<'\n';
}
return ;
}

 

Bone Collector II(01背包kth)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  7. HDU2639Bone Collector II[01背包第k优值]

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

  8. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  9. HDU2602 Bone Collector 【01背包】

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

  10. hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏

    Bone Collector Problem Description Many years ago , in Teddy's hometown there was a man who was call ...

随机推荐

  1. iOS开发隐藏tabBar的问题

    开发中遇到第一个页面需要显示tabBar,但是第二个页面不需要显示,当回到第一个页面的时候又需要显示的情况. 在第一个页面跳转到第二个页面的时候需要给第二个页面设置tabBar的隐藏 - (void) ...

  2. JavaEE中一些缩写的含义

    EJB:Enterprise JavaBeans  (企业JavaBeans) XML:Extensible Markup Lauguage (可扩展标记语言) SOAP:Simple Object ...

  3. RHEL 6.5----rsync+inotify数据同步服务

    Rsync特性: 可以镜像保存整个目录树和文件系统: 可以保持原文件的权限.时间.软硬链接等: 安装简单. 传输特点: 速度快:rsync首次同步会复制同步全部内容,以后只传输修改过的文件: 压缩传输 ...

  4. ubuntu16.04里如何正确添加用root用户来登录图形界面(图文详解)

    不多说,直接上干货! Ubuntu版本都默认不允许使用root登录,必须要改配置文件. 第一步: 首先设置root密码,利用现有管理员帐户登陆Ubuntu,在终端执行命令:sudo passwd ro ...

  5. Ionic之存储信息、取出存储信息、注销存储信息

    每一个app软件在登录的时候,都会本地存储登录信息,需要用到数据的时候,就直接在本地获取,而不是每一次应用的时候都要请求到服务器来验证登录信息,减少服务器的负担.所以在设计混合HTML5 移动应用程序 ...

  6. Windows API函数大全三

    7. API之位图.图标和光栅运算函数 BitBlt 将一幅位图从一个设备场景复制到另一个 CopyIcon 制作指定图标或鼠标指针的一个副本.这个副本从属于发出调用的应用程序 CopyImage 复 ...

  7. 用vue做一个酷炫的menu

    写在前面 最近看到一个非常酷炫的menu插件,一直想把它鼓捣成vue形式,谁让我是vue的死灰粉呢,如果这都不算爱

  8. Chrome开发者工具关于网络请求的一个隐藏技能

    这个隐藏技能的背景是,最近出于学习目的,我写了一个百度贴吧的网络爬虫,专门爬取一些指定主题的贴吧帖子. 抓取帖子用的JavaScript函数如下: function getPostByAJAX(req ...

  9. 语音行业技术领先者Nuance诚招ASR/NLP研发工程师和软件工程师

    Nuance is a leading provider of voice and language solutions for businesses and consumers around the ...

  10. 数据库系统概论(2)——Chap. 2 关系数据库基础

    数据库系统概论(2)--Chap.2 关系数据库基础 一.关系数据结构及形式化定义 1.关系 关系模型的数据结构只包含单一的数据结构--关系.在关系模型中,现实世界的实体及实体间的各种联系均用单一的结 ...