01背包(第k优解)
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
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.
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.
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
2
0
//#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优解)的更多相关文章
- 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个 然后归并排序并 ...
 - (01背包 第k优解) Bone Collector II(hdu 2639)
		
http://acm.hdu.edu.cn/showproblem.php?pid=2639 Problem Description The title of this problem i ...
 - HDU 3639 Bone Collector II(01背包第K优解)
		
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
 - 杭电 2639 Bone Collector II【01背包第k优解】
		
解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...
 - hdu2639 01背包第K优解
		
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #i ...
 - 01背包-第k优解
		
The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...
 - HDU2639Bone Collector II[01背包第k优值]
		
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
 - HDU 2639 背包第k优解
		
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
 - 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 ...
 - hdu 2639 Bone Collector II (01背包,求第k优解)
		
这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...
 
随机推荐
- @Component和@Bean以及@Autowired、@Resource
			
1. 有这么一个故事,从xml配置文件的bean说起 Spring用xml配置文件的时候(不知道阅读这篇文章的你用没用过,我用过一段时间,那是黑暗伤痛的回忆QQQ),一个xml配置文件里面有很多个 ...
 - python 文件夹下文件及文件夹名称获取
			
import os dirct = 'D:/data' dirList=[] fileList=[] files=os.listdir(dirct) #文件夹下所有目录的列表 print('files ...
 - R语言 eval(quote(x)) 和 eval(x)
			
eval() 's first argument is an expression. So if you only provide one argument, it will evaluate the ...
 - javaScript中的 call 和 apply
			
call 和apply都可以实现函数的调用 // 普通函数的调用 function foo() { console.log('foo'); } foo(); // foo foo.call(); // ...
 - 面试题常考&必考之--js中的call()和apply()
			
apply: 接受两个参数,第一个参数是要绑定给this的值,第二个参数是一个参数数组.当第一个参数为null.undefined的时候,默认指向window. call: 第一个参数是要绑定给thi ...
 - React Native 之FlatList 下拉刷新和上拉加载更多
			
接上一篇代码: 只修改了FlatListDemo.js里面的代码 import React, {Fragment,Component} from 'react'; import { SafeAreaV ...
 - mysql IN操作符 语法
			
mysql IN操作符 语法 作用:在 WHERE 子句中规定多个值.深圳大理石平台 语法:SELECT column_name(s) FROM table_name WHERE column_nam ...
 - 数位dp进阶(hdu2089,3652)
			
之前的文章已经讲过如何求1—r中的特殊数,这篇博客就来讲些进阶操作: 直接看例题(hdu2089): (题目是中文的我就不写大意了) 这题与hdu3555最大的区别就是规定了l,不再以1开始: 解决这 ...
 - Eclipse中jar包的导出与导入
			
JAR的含义: JAR是Java的档案文件,是Java Archive File的缩写.jar文件是一种压缩文件,就是以特定类型压缩包的形式存在的完整Java项目.通常通过导入jar包的方式来使用实现 ...
 - CF889E Mod Mod Mod
			
http://codeforces.com/problemset/problem/889/E 题解 首先我们观察到在每次取模的过程中一定会有一次的结果是\(a_i-1\),因为如果不是,我们可以调整, ...