题目链接【http://acm.hdu.edu.cn/showproblem.php?pid=2639】

题意:求第k大背包。

题解:利用二路归并的思想,求解第K大的值。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = ;
int dp[MAXN][], w[MAXN], v[MAXN];
int N, W, K;
int A[], B[];
void super_kth()
{
for(int i = ; i <= N; i++)
{
for(int j = W; j >= w[i]; j--)
{
for(int l = ; l <= K; l++)
{
A[l] = dp[j - w[i]][l] + v[i]; //放i
B[l] = dp[j][l];//不放i
}
int nu = , x = , y = ;
A[K + ] = -;
B[K + ] = -;
while(nu <= K && (A[x] != - || B[y] != -))
{
if(A[x] > B[y])
dp[j][nu] = A[x++];
else
dp[j][nu] = B[y++];
if(dp[j][nu] != dp[j][nu - ])//不相等的第k大背包
nu++;
}
}
}
printf("%d\n", dp[W][K]);
}
int main ()
{
int T;
scanf("%d", &T);
while(T--)
{
memset(dp, , sizeof(dp));
scanf("%d%d%d", &N, &W, &K);
for(int i = ; i <= N; i++)
scanf("%d", &v[i]);
for(int i = ; i <= N; i++)
scanf("%d", &w[i]);
super_kth();
}
return ;
}

HDU2639[背包第K大]的更多相关文章

  1. HDU2639(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大价值】

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

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

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

  4. hdu 2639 Bone Collector II(01背包 第K大价值)

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

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

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

  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. 第K大01背包

    其实这个问题,真的挺好想的,但是我咋想了那么久呢~~ 很好理解,第K大01背包一定基于01背包,dp数组也很容易的想到由dp[V]  ---->   dp[V][K],来表示背包容量是V时候的第 ...

  8. HDU 2639 01背包求第k大

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

  9. dp之01背包hdu2639(第k优解)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值.......(注意,不要 和它的第一题混 ...

随机推荐

  1. iOS 指南针的制作 附带源码

    iOS  指南针的制作  附带源码 代码下载地址: http://vdisk.weibo.com/s/HK4yE   http://pan.baidu.com/share/link?shareid=7 ...

  2. [ios2]判断retina 屏幕

    判断是否retina屏幕 #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSize ...

  3. Santa Claus and a Palindrome

    Santa Claus and a Palindrome 题目链接:http://codeforces.com/contest/752/problem/D 贪心 很自然地,可以想到,若subS不是回文 ...

  4. Spark-RDD/DataFrame/DateSet

    RDD 优点: 编译时类型安全编译时就能检查出类型错误 面向对象的编程风格直接通过类名点的方式来操作数据 缺点: 序列化和反序列化的性能开销无论是集群间的通信, 还是IO操作都需要对对象的结构和数据进 ...

  5. jq屏蔽f5

    //屏蔽F5 $(document).ready(function () { $(document).bind("keydown", function (e) { e = wind ...

  6. samba 开启

    1.查询samba服务安装好没 2.安装samba服务 3.增加以下几个条目 4.useradd smbuser 5.在重启中注意的问题 5.详细请查看 http://jingyan.baidu.co ...

  7. ios版本更新总结

    更新思路,获取APP Store 版本号与项目本地版本号对比,如果本地低于商店版本号,就提示用户更新(说明:在上架项目时请保持本地和商店版本号一致,避免检测更新问题被拒) 1.获取商店版本号,代码如下 ...

  8. gulp 安装步骤

    第一步:安装node 搭建node环境:进入官网 http://nodejs.org  ,然后点击的绿色的 install 按钮,下载完成后直接运行程序. 第二步:使用命令行 (1)输入指令:node ...

  9. USACO 3.2 Factorials

    Factorials The factorial of an integer N, written N!, is the product of all the integers from 1 thro ...

  10. python 之遍历目录树(可匹配输出特定后缀的文件)

    涉及到的模块有os, fnmatch:1.通过os模块中的方法获取dir.subdir.files,通过os.path.join可拼接成完整路径: 2.fnmatch主要通过fnmatch.fnmat ...