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. Laravel——缓存使用

    1.使用Redis类 use Illuminate\Support\Facades\Redis; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...

  2. bzoj4011 [HNOI2015]落忆枫音 拓扑排序+DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4011 题解 首先考虑如果没有那么一条被新加进来的奇怪的边的做法. 我们只需要给每一个点挑一个父 ...

  3. 【Luogu4221】[WC2018] 州区划分

    题目链接 题目描述 略 Sol 一个州合法就是州内点形成的子图中 不存在欧拉回路(一个点也算欧拉回路). 这个东西显然就状压 dp 一下: 设 \(f[S]\) 表示当前考虑了 \(S\) 这个集合内 ...

  4. Spring Batch Hello World

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11995146.html Project Directory Maven Dependency < ...

  5. linux运维、架构之路-实时同步方案

    一.inotify+rsync实时同步 1.介绍         inotify-tools是一种强大的.细粒度的.异步的文件系统事件监控机制,可以用来监控文件系统的事件.inotify-tools是 ...

  6. UOJ428. 【集训队作业2018】普通的计数题

    http://uoj.ac/problem/428 题解 神仙题. 考虑最后一定是放了一个\(1\),然后把其他位置都删掉了. 再考虑到对于序列中的每个位置都对应了一次操作. 我们可以对于每个放\(1 ...

  7. linux 挂载磁盘指令

    fdisk -l    (先df -h,如果没有xvdb盘信息,则敲这条指令) fdisk /dev/xvdb (进入对话状态,一问一答,结束后要保存w或者删除q) mkfs.ext3 /dev/xv ...

  8. CTO爆料:2019程序员最需要了解的行业前沿技术是什么?

    安森,个推CTO 毕业于浙江大学,现全面负责个推技术选型.研发创新.运维管理等工作,已带领团队开发出针对移动互联网.金融风控等行业的多项前沿数据智能解决方案. 曾任MSN中国首席架构师,拥有十余年资深 ...

  9. 十八、浏览器不能打开jenkins报告,报错Opening Robot Framework report failed

    解决方案一:(推荐) 打开jenkins----系统管理---输入:  System.setProperty("hudson.model.DirectoryBrowserSupport.CS ...

  10. leetcode 46 全排列 (python)

    给定一个没有重复数字的序列,返回其所有可能的全排列. 示例: 输入: [1,2,3]输出:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] ...