博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(01背包 第k优解) Bone Collector II(hdu 2639)
阅读量:7014 次
发布时间:2019-06-28

本文共 2173 字,大约阅读时间需要 7 分钟。

 
 
 
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:
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
 
思路:
对于求最优解的情况,我们对每一种状态只保存了该状态下的最优解,忽略了其他解,进而实现状态之间的转移,而对于求第K优解的情况呢?其实只需要保存每一种状态下的前K优解,从这K个状态进行状态间的转移,同时去重,保存当前状态的K优解即可。(感觉时间复杂度还是挺高的)
 
 
#include 
#include
#include
#include
#include
#include
#include
using namespace std;const int N = 6600;const int INF = 0x3fffffff;const long long MOD = 1000000007;typedef long long LL;#define met(a,b) (memset(a,b,sizeof(a)))int dp[N][35];int a[N], b[N], c[N];///dp[j][k] 代表容量为 j 的背包的第 k+1 优解int cmp(int a, int b){ return a > b;}int main(){ int T; scanf("%d", &T); while(T--) { int i, j, k, n, v; scanf("%d%d%d", &n, &v, &k); met(a, 0); met(b, 0); met(dp, 0); for(i=1; i<=n; i++) scanf("%d", &a[i]); for(i=1; i<=n; i++) scanf("%d", &b[i]); for(i=1; i<=n; i++) { for(j=v; j>=b[i]; j--) { int w = 0; for(int z=0; z

 

转载于:https://www.cnblogs.com/YY56/p/5476797.html

你可能感兴趣的文章
Paint.FontMetrics
查看>>
初步理解require.js模块化编程
查看>>
计算机网络(一)
查看>>
asyncsocket的用法
查看>>
【贪心】HDU 1257
查看>>
nodejs 解决跨域
查看>>
04 变量和参数介绍
查看>>
C# 关于LINQ基础随笔
查看>>
ASP.NET MVC 3 Razor 视图引擎 基本语法
查看>>
C# 关于XML的简单操作实例
查看>>
ggplot2:画世界地图和中国地图 合并数据 增添信息 标记
查看>>
火狐开发----Web开发者工具
查看>>
修改mysql表操作
查看>>
简单背包问题
查看>>
SPOJ Problem 4452:Simple Arithmetics II
查看>>
c# 使用 Tchart控件之数据绑定
查看>>
php 将其他地图位置坐标 转换成 百度地图坐标
查看>>
HTML5复习
查看>>
Latex Development in Mac OS
查看>>
可用来获取HttpServletResponse响应的数据的包装器类
查看>>