题干:

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

题目大意:
01背包的第k个最大价值。注意,两种不同方法得到相同价值是算作同一个种。这意味着,可以得到的价值序列将是一个严格递减的序列,从第1个最大值,第2个最大值.....第k个最大值。 
如果不同值的总数小于K,就输出"0"(不带引号)

解题报告:

直接用set维护前k大就可以了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
set<int> dp[1005];
int n,V,K;
int w[MAX],v[MAX];
int main()
{int T;cin>>T;while(T--) {cin>>n>>V>>K;for(int i = 0; i<=V; i++) dp[i].clear(),dp[i].insert(0);for(int i = 1; i<=n; i++) scanf("%d",v+i);for(int i = 1; i<=n; i++) scanf("%d",w+i);for(int i = 1; i<=n; i++) {for(int j = V; j>=w[i]; j--) {auto it = dp[j-w[i]].begin();for(;it!=dp[j-w[i]].end(); it++) {dp[j].insert(*it + v[i]);}while(dp[j].size() > K) dp[j].erase(dp[j].begin());}}printf("%d\n",*dp[V].begin());}return 0 ;
}

【HDU - 2639】Bone Collector II (第K大背包,dp,STLset)相关推荐

  1. HDU - 2639 Bone Collector II

    HDU - 2639 Bone Collector II dp之难,难于上青天. The title of this problem is familiar,isn't it?yeah,if you ...

  2. HDU 2639 Bone Collector II(01背包-第K优决策)

    Description 给出n件物品的价值和体积,问在总体积不超过v时的第k大价值 Input 第一行为用例组数T,每组用例第一行为三个整数n,v和k,第二行n个整数表示这n件物品的价值,第三行n个整 ...

  3. HDU 2639 Bone Collector II (dp)

    题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...

  4. HDOJ 2639 Bone Collector II (背包)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2639 第K优解问题 其基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序 ...

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

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

  6. hdu 2602 Bone Collector 01背包

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

  7. HDU 2602 Bone Collector DP(01背包)

    Bone Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Desc ...

  8. hdu 2602 Bone Collector

    终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...

  9. HDU2602 Bone Collector【0/1背包+DP】

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

最新文章

  1. 数学学渣必备!拍照上传,分步求解,微软解题神器拯救你
  2. 用Python分析《工作细胞》的一万多条评论后,非漫迷也要入番了
  3. python方法和函数的格式是完全一样的_【python基础语法】常用内置函数、关键字、方法和之间的区别(小结)...
  4. php错误提示:date_default_timezone_get
  5. 区别CALL SCREEN/SET SCREEN/LEAVE TO SCREEN
  6. MySQL 出现 The table is full 的解决方法
  7. 年终总结 | 从Oracle到MySQL大家最关注的竟然是...
  8. 【Linux】Linux查看机器负载-IO负载
  9. 敏捷开发框架_力软敏捷开发框架,不需要程序员也能做的开发工具
  10. Android零基础入门第56节:翻转视图ViewFlipper打造引导页和轮播图
  11. NVIDIA显卡刷BIOS教程,秒变超频显卡,将显卡性能发挥到极致!
  12. SPSS入门教程—问卷的信度量化分析
  13. 第十届全国大学生光电设计大赛分析前瞻(一文看懂光电设计大赛创意赛,做好准备)
  14. 并发编程-线程卡死问题实践
  15. 【AviUtl】动画效果,简易Glitch++(派生),学习笔记
  16. Oracle 企业管理器DataBase Control使用说明
  17. mysql保留小数位数函数
  18. 一家之言:中国IT人员创业存在的问题
  19. PLC编程软件在线调试程序的方法
  20. 微机原理笔记03-指令系统

热门文章

  1. 小议同步IO :fsync与fdatasync
  2. [Leedcode][JAVA][第287题][寻找重复数][HashSet][二分查找][快慢指针]
  3. python多线程并发写入_Python多线程并发的简单测试
  4. base64 转文件_PHP伪协议与文件包含
  5. 华为swot分析2020_科技口译现场:华为2020全球分析师大会
  6. 怎么检查计算机网络是连接,怎么检测网络打印机是否与电脑连接成功【检测方法】...
  7. 1006 换个格式输出整数 (15 分)
  8. C# 派生类的构造函数
  9. STM32 HAL库 .c/.h 文件介绍
  10. mysql memcache redis_redis,mysql,memcache的區別與比較,redis兩種數據存儲持久化方式