HUD 2639 Bone Collector II
Bone Collector II
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5463 Accepted Submission(s):
2880
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.
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.
the total value (this number will be less than 231).
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int T;
int dp[][];
cin >> T;
priority_queue<int>q;//默认从大到小排
while (T--)
{
memset(dp, , sizeof(dp));
int n, vv, kk;
cin >> n >> vv >> kk;
int i, j, k;
int v[], w[];
for (i = ; i <= n; i++)
cin >> v[i];
for (i = ; i <= n; i++)
cin >> w[i];
for (i = ; i <= n; i++)
{
for (j = vv; j >= w[i]; j--)//01背包的循环
{
while (!q.empty()) q.pop();
for (k = ; k <= kk; k++)
{//dp[j][1....k]和dp[j-w[i]][1.....k]+v[i]放进队列
q.push(dp[j][k]);
q.push(dp[j - w[i]][k] + v[i]);
}
k = ;
while ()
{
if (q.empty() || k == kk+) break;
if (k > && q.top() != dp[j][k-])
{//这一步避免重复, q.top() == dp[j][k-1]要排除
dp[j][k] = q.top(); k++;
}
else if (k == )
{
dp[j][k] = q.top(); k++;
}
q.pop();
}
}
}
cout << dp[vv][kk] << endl;
}
return ; }
HUD 2639 Bone Collector II的更多相关文章
- HDU 2639 Bone Collector II(01背包变形【第K大最优解】)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 2639 Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 2639 Bone Collector II(01背包 第K大价值)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 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 ...
- 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 ...
- 杭电 2639 Bone Collector II【01背包第k优解】
解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...
- hdu 2639 Bone Collector II (01背包,求第k优解)
这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...
- HDU 2639 Bone Collector II(01背包变型)
此题就是在01背包问题的基础上求所能获得的第K大的价值. 详细做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,事实上就 ...
- HDU - 2639 Bone Collector II (01背包第k大解)
分析 \(dp[i][j][k]\)为枚举到前i个物品,容量为j的第k大解.则每一次状态转移都要对所有解进行排序选取前第k大的解.用两个数组\(vz1[],vz2[]\)分别记录所有的选择情况,并选择 ...
随机推荐
- AE项目打包
Holinz AE项目打包 打包详细信息:Setup Factory 7.0打包软件,VS2005+AE92下的Winform项目1.依赖项: Dot Net Framework20 AO ...
- jenkins自动化打包部署
请参考: http://m.blog.csdn.net/article/details?id=50518959 1.启动 jenkins.war ,打开首页 192.168.158.129:8080 ...
- anu - controlledComponent
/** input, select, textarea这几个元素如果指定了value/checked的**状态属性**,就会包装成受控组件或非受控组件 受控组件是指,用户除了为它指定**状态属性**, ...
- webView的使用以及总结
一.webview是什么? Android WebView 做为承载网页的载体控件,他在网页显示的过程中会产生一些事件,并回调给我们的应用程序,以便我们在网页加载过程中做应用程序想处理的事情.比如说客 ...
- Port of FreeModbus to STM32
/********************************************************************************* * Port of FreeMod ...
- OK335xS Linux Qt make: icpc: Command not found
OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...
- win10笔记本实现双屏显示的自如切换
前言 使用电脑的过程中想一边看内容,一边进行编辑,这就涉及到双屏显示并实现扩展分屏,本文就介绍一下这些操作. 工具 win10-thinkpad-E470:另一块显示屏(博主的是戴尔的显示器):一条外 ...
- 利用asynchttpclient开源项目来把数据提交给服务器
可以通过github去查找asynchttpclient,并下载源代码,并加载到自己的工程中. 1.利用get方法提交 2.利用post方法来提交
- [LeetCode&Python] Problem 821. Shortest Distance to a Character
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- [LeetCode&Python] Problem 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...