Bone Collector II

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

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
 
Source
 
题意:2602的改版 与普通01背包不同是求第k大价值
 
题解:增加一维  存储 dp[i][w] 容量为i的背包存放的物品的第w大价值和 
        增加一步 两个序列合并的过程 形成新的k大
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int t;
int n,v,k;
int a[];
int b[];
int we[],va[];
int dp[][];
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=;i<=t;i++)
{
memset(we,,sizeof(we));
memset(va,,sizeof(va));
memset(dp,,sizeof(dp));
scanf("%d %d %d",&n,&v,&k);
for(int j=;j<=n;j++)
scanf("%d",&we[j]);
for(int j=;j<=n;j++)
scanf("%d",&va[j]);
for(int j=;j<=n;j++)
{
for(int l=v;l>=va[j];l--)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int m=;m<=k;m++)
{
a[m]=dp[l][m];
b[m]=dp[l-va[j]][m]+we[j];
}
a[k+]=-;
b[k+]=-;
int x=,y=,w=;
while(w<=k&&(x<=k||y<=k))//合并的过程
{
if(a[x]>b[y])
{
dp[l][w]=a[x];
x++;
}
else
{
dp[l][w]=b[y];
y++;
}
if(w==||dp[l][w]!=dp[l][w-])
w++;
}
}
}
cout<<dp[v][k]<<endl;
}
}
return ;
}

HDU 2639 01背包求第k大的更多相关文章

  1. HDU 2639(01背包求第K大值)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2639 Bone Collector II Time Limit: 5000/2000 MS (Jav ...

  2. HDU 2639(01背包第K大)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 http://blog.csdn.net/lulipeng_cpp/article/details/758 ...

  3. Bone Collector II---hdu2639(01背包求第k优解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639求01背包的第k大解.合并两个有序序列 选取物品i,或不选.最终的结果,是我们能在O(1)的时间内 ...

  4. 关于01背包求第k优解

    引用:http://szy961124.blog.163.com/blog/static/132346674201092775320970/ 求次优解.第K优解 对于求次优解.第K优解类的问题,如果相 ...

  5. HDU 2639 01背包(分解)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 01背包第k优解,把每次的max分步列出来即可 #include<stdio.h> #incl ...

  6. Bone Collector II HDU - 2639 01背包第k最大值

    题意: 01背包,找出第k最优解 题解: 对于01背包最优解我们肯定都很熟悉 第k最优解的话也就是在dp方程上加一个维度来存它的第k最优解(dp[i][j]代表,体积为i能获得的第j最大价值) 对于每 ...

  7. HDU 1171 Big Event in HDU【01背包/求两堆数分别求和以后的差最小】

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  8. HDU 5249 离线树状数组求第k大+离散化

    KPI Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. poj 2985 The k-th Largest Group 树状数组求第K大

    The k-th Largest Group Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 8353   Accepted ...

随机推荐

  1. python应用:爬虫实例(动态网页)

    以爬取搜狗图片为例,网页特点:采用“瀑布流”的方式加载图片,图片的真实地址存放在XHR中 #-*-coding:utf8-*- import requests import urllib import ...

  2. struts2架构网站漏洞修复详情与利用漏洞修复方案

    struts2从开发出来到现在,很多互联网企业,公司,平台都在使用apache struts2系统来开发网站,以及应用系统,这几年来因为使用较多,被攻击者挖掘出来的struts2漏洞也越来越,从最一开 ...

  3. 小程序开发-7-访问api数据与ES6在小程序中的应用

    访问API数据与ES6在小程序中的应用 看待组件的两种观点 组件复用 代码分离-(特别重要) 不能在一个页面写所有的代码,代码分离具有很强的可读性.可维护性 Blink Api 介绍与测试API ur ...

  4. kafka单机部署文档

    单机Kafka部署文档 最简单的使用方式,单机,使用自带的zookeeper 1.解压 下载地址:http://pan.baidu.com/s/1i4K2pXr tar –zxvf kafka_2.1 ...

  5. 如何理解Java中参数传递只能传值?

    以前学习C#的时候,是完全在工作岗位上学习,一些底层较为深入的道理都不是很清楚.如今学习了Java,对于Java参数传递只能传值,不能传引用(指针)感到很困惑,在C#中不是常常说把某个引用传递到函数中 ...

  6. 《数据结构与算法分析:C语言描述》读书笔记

    我们数据结构的课用了这本英文教材,作者是Mark Allen Weiss.总体来说比<算法导论>简单很多,但内容上交集非常大.其实是因为去掉了大多数证明和数学,对于没有耐心看符号和公式的人 ...

  7. java存储位置经典例子

    String a="a";String b="b";String c="ab";String d="ab";String ...

  8. cmd命令笔记

    查看端口信息:netstat -ano eg. netstat -ano|findstr 0.0.0.0:443 根据pid查看进程信息等:wmic process get name,executab ...

  9. 树莓派配置 USB 无线网卡

    树莓派配置 USB 无线网卡来上网的过程. 本人使用的USB无线网卡型号:EP-N8508GS(树莓派专用型号) 一.检查 USB 无线网卡是否已经正确识别 将无线 USB 网卡插入树莓派后启动树莓派 ...

  10. wpa_supplicant 初始化

    几个重要的结构体介绍: 1. struct wpa_interface --- Parameters for wpa_supplicant_add_iface(). wpa_interface对应网络 ...