Bone Collector II

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1334    Accepted Submission(s): 666 
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
 
// dp[s][i][k]  表示在用了 s 空间 i 件物品后排在第k位的值是多少 

dp[s][i][1..k] 在 dp[s][i][1..k] 和 dp[s-s[i]][i-1][1..k] 这2k 个数据中找到前 k 名就是了

就像学校想知道一个年级的前十名 ,只要知道每个班的前十 而过程则是只要比较每2个班的前十、就可以知道全校前十 
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int dp[][];
int s[],p[];
int main()
{
int N,V,K;
int T;
scanf("%d",&T);
while(T--){
int i,j,k;
scanf("%d %d %d",&N,&V,&K);
int t1[],t2[];
for(i=;i<=N;i++)
scanf("%d",&p[i]);
for(i=;i<=N;i++)
scanf("%d",&s[i]); memset(dp,,sizeof(dp)); for(i=;i<=N;i++){ for(j=V;j>=s[i];j--){ for(k=;k<=K;k++)
{
t1[k]=dp[j-s[i]][k]+p[i];
t2[k]=dp[j][k];
}
t1[k]=t2[k]=-;
int a=,b=;
for(k=;(a<=K||b<=K)&&k<=K;){
if(t1[a]>t2[b])
dp[j][k]=t1[a++];
else
dp[j][k]=t2[b++];
if(dp[j][k]!=dp[j][k-])
k++;
}
}
}
printf("%d\n",dp[V][K]);
} return ;
}

hdu 2639 Bone Collector II的更多相关文章

  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 2639 Bone Collector II(01背包 第K大价值)

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

  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. HDU 2639 Bone Collector II【01背包 + 第K大价值】

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  5. hdu 2639 Bone Collector II (01背包,求第k优解)

    这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...

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

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

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

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

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

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

  9. HDU - 2639 Bone Collector II 题解

    题目大意 一个人收藏骨头,有 n 个骨头,每个骨头有体积和价值,问能够装在容量为 V 的背包中,能获得的第 k 大(去重后)价值是多少. 样例 样例输入 1 5 10 2 1 2 3 4 5 5 4 ...

随机推荐

  1. spring接收参数

    public class LogonModel { private String UserName; private String Password; public String getUserNam ...

  2. ThinkPHP I方法

    ThinkPHP的I方法是3.1.3版本新增的,如果你是之前的3.*版本的话,可以直接参考使用3.1快速入门教程系列的变量部分. 概述 正如你所见到的一样,I方法是ThinkPHP众多单字母函数中的新 ...

  3. Entity Framework 学习笔记(一)安装

    1.通过 VS2013 下载,这个没有限制,因为我用的vs是2013 Entity Framework包

  4. 从JAVA多线程理解到集群分布式和网络设计的浅析

    对于JAVA多线程的应用非常广泛,现在的系统没有多线程几乎什么也做不了,很多时候我们在何种场合如何应用多线程成为一种首先需要选择的问题,另外关于java多线程的知识也是非常的多,本文中先介绍和说明一些 ...

  5. 使用maven配置基本Mybatis

    Mybatis 也称为是ibatis,主要体现在普通.底层SQL查询.存储过程.高级映射的持久化框架! 优点:                                     1.消除了几乎所 ...

  6. ssh scp访问ipv6地址

    从这里学来的.http://blog.mattandanne.org/2012/01/sftpscp-and-ipv6-link-local-addresses.html当采用ipv6的地址去连接另外 ...

  7. 1185: [HNOI2007]最小矩形覆盖 - BZOJ

      就是一道凸包(枚举凸包的边作为矩形的一条边)的裸题,只是不太好打,所以犹豫到今天才打 不说了,说起AC都是泪啊,因为没有精度判断,没有判重(算距离时除0了)错了好久 拍了好久都和标称是一样的,因为 ...

  8. fiddler 插件开发

    本文主要讲解使用.net C#语言开发Fiddler插件. 1.在Fiddler 会话列表中添加自定义列 使用FiddlerApplication.UI.lvSessions.AddBoundColu ...

  9. Python 开源异步并发框架的未来

    http://segmentfault.com/a/1190000000471602 开源 Python 是开源的,介绍的这几个框架 Twisted.Tornado.Gevent 和 tulip 也都 ...

  10. c#基础精华01(强调代码规范,虚方法,抽象方法,接口)

    强调代码规范 规则(法律,必须遵守否则报错) 语法 规范(道德,大家都喜欢有道德的人.) 注释//,/**/,/// 骆驼命名 :第一个单词首字母小写,之后的单词首字母大写 userName.user ...