hdu-2639 Bone Collector II---第k大背包】的更多相关文章

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): 3355    Accepted Submission(s): 1726 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): 1334    Accepted Submission(s): 666 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
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&…
分析 \(dp[i][j][k]\)为枚举到前i个物品,容量为j的第k大解.则每一次状态转移都要对所有解进行排序选取前第k大的解.用两个数组\(vz1[],vz2[]\)分别记录所有的选择情况,并选择其中前k大的更新当前的dp[i][k].因为dp[i]满足递增的特点,所以可以对两个数组顺序比较选择. #include<bits/stdc++.h> using namespace std; const int maxn = 1e3+5; const int INF = 0x3f3f3f3f;…
题意: 数据是常规的01背包,但是求的不是最大容量限制下的最佳解,而是第k佳解. 思路: 有两种解法: 1)网上普遍用的O(V*K*N). 2)先用常规01背包的方法求出背包容量限制下能装的最大价值m,再以m为背包容量再进行一次01背包,dp[j]表示当物品的组合价值为j时,它们的体积之和的最小量.那么就求出了所有可能的价值,从1-m都有,但是其中一些是求不出来的,也就是骨头的价值不能组合成这个数字,那么就得过滤掉. #include <iostream> #include <cstdi…
题目链接 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…
此题就是在01背包问题的基础上求所能获得的第K大的价值. 详细做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,事实上就是2个数组合并之后排序,可是实际做法最好不要怎么做.由于你不知道总共同拥有多少种.而我们最多仅仅须要前K个大的即可了(由于可能2个数组加起来的组合数达不到K个),假设所有加起来数组开多大不清楚,所以能够选用归并排序中把左右2个有序数组合并成一个有序数组的方法来做.就是用2个变量去标记2个有序数组的头…
题目大意 一个人收藏骨头,有 n 个骨头,每个骨头有体积和价值,问能够装在容量为 V 的背包中,能获得的第 k 大(去重后)价值是多少. 样例 样例输入 1 5 10 2 1 2 3 4 5 5 4 3 2 1 样例输出 1 12 样例输入 2 5 10 12 1 2 3 4 5 5 4 3 2 1 样例输出 2 2 分析 跑暴力显然不优秀,每种物品可选可不选,最多 \(2^n\) 种不同的方案,也就对应这么多价值,显然如果都存下再排序输出结果,简单了事,但是显然时间和空间都承受不住. 当然在跑…