Bone Collector II(HDU 2639 DP)
Bone Collector II
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3471 Accepted Submission(s): 1792
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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int dp[][];
int val[],vol[];
int n,v,K;
int a[],b[];
int main()
{
freopen("in.txt","r",stdin);
int i,j,k;
int x,y,z;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&v,&K);
for(i=;i<=n;i++)
scanf("%d",&val[i]);
for(i=;i<=n;i++)
scanf("%d",&vol[i]);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
for(j=v;j>=vol[i];j--)
{
for(k=;k<=K;k++) //记录每种状态的k优解
{
a[k]=dp[j][k];
b[k]=dp[j-vol[i]][k]+val[i];
}
a[k]=b[k]=-; //存储的内容已经按照从小到大排序好了,然后合并到dp数组中去
x=y=z=;
while(z<=K&&(a[x]!=-||b[y]!=-))
{
if(a[x]>b[y])
{
dp[j][z]=a[x];
x++;
}
else
{
dp[j][z]=b[y];
y++;
}
if(dp[j][z-]!=dp[j][z])
z++;
}
}
}
printf("%d\n",dp[v][K]);
}
return ;
}
Bone Collector II(HDU 2639 DP)的更多相关文章
- (01背包 第k优解) Bone Collector II(hdu 2639)
http://acm.hdu.edu.cn/showproblem.php?pid=2639 Problem Description The title of this problem i ...
- Bone Collector II(hdu 2639)
题意:求01背包的第k最优值 输入:第一行为T,下面是T组数据,每组数据有n,m,k 代表n件物品,m容量,和题目要求的k,下一行是n个物品的价值,再一行是n个物品的体积 输出:T行答案 /* 类似于 ...
- Bone Collector II(01背包kth)
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大价值)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3639 Bone Collector II(01背包第K优解)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU2639Bone Collector II(01背包变形)
01背包,求第k大. 以前看k短路的时候看过代码以为懂了 = =结果还是跑去看了别人的代码才会.果然要自己写一遍才行啊 0.0难得1A.. 每次把可能的2k种求出来,求前k个.注意要不一样的k个数.. ...
- HDU 2639 Bone Collector II (dp)
题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...
- hdu 2639 Bone Collector II (01背包,求第k优解)
这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...
- [HDOJ2639]Bone Collector II(第k优01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几 ...
随机推荐
- 用 C 语言编写 Windows 服务程序的五个步骤
Windows 服务被设计用于需要在后台运行的应用程序以及实现没有用户交互的任务.为了学习这种控制台应用程序的基础知识,C(不是C++)是最佳选择.本文将建立并实现一个简单的服务程序,其功能是查询系统 ...
- (转)centos6起/etc/syslog.conf不再有!而是/etc/rsyslog.conf代替!
centos6起/etc/syslog.conf不再有!而是/etc/rsyslog.conf代替!
- Xs and Os Referee
Xs and Os Referee 1 def checkio(game_result): 2 winner = 'D' 3 4 for row in game_result: 5 if row[0] ...
- B/S 网站技术选型
Windows平台: http://www.asp.net, http://www.asp.net/mvc Web技术 http://msdn.microsoft.com/ef 数据访问中间件 htt ...
- poj1363
堆栈的模拟,给定序列,1,2,3,4,...判断堆栈出栈顺序是否合法 5 //5个数入栈1 2 3 4 5 //出栈顺序5 4 1 2 3 //出栈顺序0 //5个数的结束6 //6个数的入栈6 5 ...
- 【HDU1162】Eddy's picture(MST基础题)
很基础的点坐标MST,一不留神就AC了, - - !! #include <iostream> #include <cstring> #include <cstdlib& ...
- IDX爱定客 | 氪加
IDX爱定客 | 氪加 个性化定制鞋网站,在线定制只需三分钟
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
- sleep()函数的的意义
===============WINDOWS平台下:====================== 关于VOID Sleep(DWORD dwMilliseconds);函数,许多人都觉得,它是告诉系统 ...
- Windows Live Writer 代码插件改造
源码和插件都在后面,如果不想看我神神叨叨的可以直接到文章后面下载 一 .找插件 在使用Windows Live Writer 经常要用到插入代码的功能,根据博客园中教程,分别使用了: WindowsL ...