Bone Collector II

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

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
 
思路:把放第i个物品看成序列a,不放序列看成序列b,合并依次组成k解。相当于把2的n次方情况排序取前30种。
 
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int dp[][];
int val[] , vol[]; int main()
{
int t ;
scanf("%d" , &t);
while(t--)
{
int n , v , kk , a[] , b[];
scanf("%d%d%d" , &n , &v , &kk);
memset(dp , , sizeof(dp));
for(int i = ; i <= n ; i++)
{
scanf("%d" , &val[i]);
}
for(int i = ; i <= n ; i++)
{
scanf("%d" , &vol[i]);
}
for(int i = ; i <= n ; i++)
{
for(int j = v ; j >= vol[i] ; j--)
{
for(int k = ; k <= kk ; k++)//将所有解存起来
{
a[k] = dp[j][k];
b[k] = dp[j-vol[i]][k] + val[i] ;
}
// 对所有解进行排序
a[kk+] = - ;
b[kk+] = - ;
int k = ;
int x = , y = ;
while(k <= kk && (a[x] != - || b[y] != -))
{
if(a[x] > b[y])
{
dp[j][k] = a[x];
x++ ;
}
else
{
dp[j][k] = b[y];
y++;
}
if(dp[j][k] != dp[j][k-]) k++ ;
}
}
}
cout << dp[v][kk] << endl ; } return ;
}

01背包(第k优解)的更多相关文章

  1. HDU 2639 (01背包第k优解)

    /* 01背包第k优解问题 f[i][j][k] 前i个物品体积为j的第k优解 对于每次的ij状态 记下之前的两种状态 i-1 j-w[i] (选i) i-1 j (不选i) 分别k个 然后归并排序并 ...

  2. (01背包 第k优解) Bone Collector II(hdu 2639)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639       Problem Description The title of this problem i ...

  3. HDU 3639 Bone Collector II(01背包第K优解)

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

  4. 杭电 2639 Bone Collector II【01背包第k优解】

    解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...

  5. hdu2639 01背包第K优解

    #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #i ...

  6. 01背包-第k优解

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

  7. HDU2639Bone Collector II[01背包第k优值]

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

  8. HDU 2639 背包第k优解

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

  9. 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 ...

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

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

随机推荐

  1. 将windows下的文件复制到linux

    首先先将你xshell配置好用户名及密码等,必须使用有权限下载的账号进行操作. 使用 yum provides */rz 这条命令,查看你系统自带的软件包的信息.可以看到下方有具体的输出. 2 在输出 ...

  2. ubuntu16.04 安装mysql

    安装mysql 1.sudo apt-get install mysql-server 2.sudo apt install mysql-client 3.sudo apt install libmy ...

  3. man cal

    CAL(1)                                                                  CAL(1) NAME       cal - 显示一个 ...

  4. Java语言Lang包下常用的工具类介绍_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 无论你在开发哪中 Java 应用程序,都免不了要写很多工具类/工具函数.你可知道,有很多现成的工具类可用,并且代码质量都 ...

  5. [USACO19JAN]Shortcut题解

    本题算法:最短路树 这是个啥玩意呢,就是对于一个图,构造一棵树,使从源点开始的单源最短路径与原图一模一样.怎么做呢,跑一边Dijkstra,然后对于一个点u,枚举它的边,设当前的边为cur_edge, ...

  6. GeoServer-2.12安装MbTiles扩展插件

  7. 大数据笔记(十二)——使用MRUnit进行单元测试

    package demo.wc; import java.util.ArrayList; import java.util.List; import org.apache.hadoop.io.IntW ...

  8. GitHub最著名的20个Python机器学习项目

    GitHub最著名的20个Python机器学习项目 我们分析了GitHub上的前20名Python机器学习项目,发现scikit-Learn,PyLearn2和NuPic是贡献最积极的项目.让我们一起 ...

  9. 【洛谷P1983 车站分级】

    这题好像是个蓝题.(不过也确实差不多QwQ)用到了拓扑排序的知识 我们看这些这车站,沿途停过的车站一定比未停的车站的级别高 所以,未停靠的车站向已经停靠的车站连一条边,入度为0的车站级别就看做1 然后 ...

  10. Oracle OLAP

    w 国产商业智能 BI 这 20 年(1997-2017)| 天善智能  http://mp.weixin.qq.com/s/VJURX2qhmL0Uj1dctMyEig 1997-2001年,萌芽阶 ...