http://acm.hdu.edu.cn/showproblem.php?pid=2639 题目大意是,往背包里赛骨头,求第K优解,在普通01背包的基础上,增加一维空间,那么F[i,v,k]可以理解为前i个物品,放入容量v的背包时,第K优解的值.时间复杂度为O(NVK). Talk is cheap. 看代码吧. import java.util.Scanner; public class BoneCollector { public static void main(String[] sur…
/* 01背包第k优解问题 f[i][j][k] 前i个物品体积为j的第k优解 对于每次的ij状态 记下之前的两种状态 i-1 j-w[i] (选i) i-1 j (不选i) 分别k个 然后归并排序并且去重生成ij状态的前k优解 */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 1010 using namespace std; ],x[maxn],y[maxn],a,b,z; i…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4178    Accepted Submission(s): 2174 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took pa…
http://acm.hdu.edu.cn/showproblem.php?pid=2639       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 does…
解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[v-c[i]]+w[i]中的最大值,但是现在要求第k大的值,我们就分别用两个数组保留f[v]的前k个值,f[v-c[i]]+w[i]的前k个值,再将这两个数组合并,取第k名. 即f的数组会增加一维. http://blog.csdn.net/lulipeng_cpp/article/details/…
题意: 01背包,找出第k最优解 题解: 对于01背包最优解我们肯定都很熟悉 第k最优解的话也就是在dp方程上加一个维度来存它的第k最优解(dp[i][j]代表,体积为i能获得的第j最大价值) 对于每一个物品只有两种选择情况 1.把这个物品加入背包 2.不要这个物品 那么它的前k种最优解也是由n种物品的这两个选择组成的 假设总体积是4,现在有两种物品,求第2最大值 1.体积1,价值3 2.体积1,价值2 最开始dp状态: 体积:   1  2  3  4 第1最大值:0  0  0  0 第2最…
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.c…
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; ][],val[],vol[], A[],B[]; int main() { int T,n,v,K,k; scanf("%d",&T); while(T--) { scanf("%d%d%…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4229    Accepted Submission(s): 2205 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4824    Accepted Submission(s): 2514 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意: 01背包第k优解, 背包九讲原题.“ 对于求次优解.第K优解类的问题,如果相应的最优解问题能写出状态转移方程.用动态规划解决,那么求次优解往往可以相同的复杂度解决,第K优解则比求最优解的复杂度上多一个系数K. 其基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并.这里仍然以01背包为例讲解一下. 首先看01背包求最优解的状态转移方程:f[i][v…
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.c…
这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004.blog.163.com/blog/static/8835120220138611342496/http://hi.baidu.com/chenyun00/item/1c6c44318acc8bfaa88428c7 #include <iostream> #include <cstdio&…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639求01背包的第k大解.合并两个有序序列 选取物品i,或不选.最终的结果,是我们能在O(1)的时间内,判定对于体积j,是否应当选取第i件物品. 我们在这里作出了最优的选择.那被我们抛弃的选择呢?他很可能是次优解,第三优解,无论怎样,他都对我们本题求前K优解,起到了重要的作用! #include<stdio.h> #include<string.h> #include<algor…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几乎一样,只是我们只需要关注每一次取的前k大个即可. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3355    Accepted Submission(s): 1726 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
引用:http://szy961124.blog.163.com/blog/static/132346674201092775320970/ 求次优解.第K优解 对于求次优解.第K优解类的问题,如果相应的最优解问题能写出状态转移方程.用动态规划解决,那么求次优解往往可以相同的 复杂度解决,第K优解则比求最优解的复杂度上多一个系数K. 其基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并.这里仍然以01背包为例讲解一下. 首先看01背包求最优解的状态转移方程…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4739    Accepted Submission(s): 2470 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took pa…
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 par…
http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值.......(注意,不要 和它的第一题混起来,它第一行是价值,再是体积) 思路:首先dp[i][j]代表的是在体积为i的时候第j优解为dp[i][j]......那么,我们就可以这样思考,i对应体积,那么如果只是一维的dp[i],代表的应该是体积为i时的最大值,那么同理,dp[i][1]代表的是体积为i时的最大值,那么我们就可以退出两种动…
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j \right] = \max \left\{ {dp\left[ j \right],dp\left[ {j - a\left[ i \right].w} \right] + a\left[ i \right].v} \right\}\] 如果要求第K优解,那么状态 dp[j] 就应该是一个大小为…
From easthong ☆背包的第k优解                 描述 Description     DD 和好朋友们要去爬山啦!他们一共有 K 个人,每个人都会背一个包.这些包的容量是相同的,都是 V.可以装进背包里的一共有 N 种物品,每种物品都有给定的体积和价值. 在 DD 看来,合理的背包安排方案是这样的: 1. 每个人背包里装的物品的总体积恰等于包的容量.  2. 每个包里的每种物品最多只有一件,但两个不同的包中可以存在相同的物品.  3. 任意两个人,他们包里的物品清单…
题目描述--->p1858 多人背包 分析: 很明显,这题是背包问题的一种变形. 求解 次优解or第k优解. 表示刚开始有点懵,看题解也看不太懂. 又中途去补看了一下背包九讲 然后感觉有些理解,但还是不算太清楚. 所以自己思考了一下.(应该算是大致理解了意思. 来分享一下思路. 题解里都说是裸的此类问题,并没有给出解释. (给出的解释也大多是背包九讲里的一些抽象定义 前置知识 首先根据01背包的递推式:(这里按照一维数组来讲) (v[i]代表物品i的体积,w[i]代表物品i的价值). \(f(j…
题目http://acm.hdu.edu.cn/showproblem.php?pid=2639 分析:这是求第K大的01背包问题,很经典.dp[j][k]为背包里面装j容量时候的第K大的价值. 从普通01背包中可以知道最大价值dp[j]是由dp[j]和dp[j-c[i]]+w[i]决定的.那么可以知道 dp[j][k]也是有dp[j][k]和dp[j-c[i]][k]来决定的. 求次优解.第K优解: 对于求次优解.第K优解类的问题,如果相应的最优解问题能写出状态转移方程.用动态规划解决,那么求…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值 分析:dp[i][j][k]表示前i个物品容积为j时的第k优解.那么对于每种状态dp[i][j]都需要维护好前k优解. 每次根据前k优解进行每种取或不取第i件物品,用数组a记录取第i件物品,数组b记录不取,这样 数组a,b了所有能组成j的x种解,最后在x里取前k优解记录下来就好.剩下的肯定不是前k优解了... #include…
附题目链接:Bone Collector II 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 t…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3437    Accepted Submission(s): 1773 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
K优解 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定n个行数,每行m个.在每行中选出一个数来,求出前 k 小的异或和. Input 第一行 3 个正整数 n,m,k. 接下来 n 行,每行 m 个非负整数,第 i 行第 j 个为权值a[i][j]. Output 一行一个数表示答案. Sample Input 3 2 2 11 21 9 25 17 19 Sample Output 2 HINT n*m<=300000,k<=3…
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 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
题目链接 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 l…