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

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: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.

 
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解;
 #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)的更多相关文章

  1. (01背包 第k优解) Bone Collector II(hdu 2639)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639       Problem Description The title of this problem i ...

  2. Bone Collector II(hdu 2639)

    题意:求01背包的第k最优值 输入:第一行为T,下面是T组数据,每组数据有n,m,k 代表n件物品,m容量,和题目要求的k,下一行是n个物品的价值,再一行是n个物品的体积 输出:T行答案 /* 类似于 ...

  3. 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 ...

  4. hdu 2639 Bone Collector II(01背包 第K大价值)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDU 3639 Bone Collector II(01背包第K优解)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDU2639Bone Collector II(01背包变形)

    01背包,求第k大. 以前看k短路的时候看过代码以为懂了 = =结果还是跑去看了别人的代码才会.果然要自己写一遍才行啊 0.0难得1A.. 每次把可能的2k种求出来,求前k个.注意要不一样的k个数.. ...

  7. 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 ...

  8. hdu 2639 Bone Collector II (01背包,求第k优解)

    这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...

  9. [HDOJ2639]Bone Collector II(第k优01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几 ...

随机推荐

  1. [UVA] 784 - Maze Exploration

      Maze Exploration  A maze of rectangular rooms is represented on a two dimensional grid as illustra ...

  2. [TYVJ] P1238 路径

    路径 描述 Description 图是由一组顶点和一组边组成的.一条边连接两个顶点.例如,图1表示了一个有4个顶点V.5条边的图.图中,每条边e是有方向的,方向从起点到终点,并且每条边都有价值.用整 ...

  3. android:layout_gravity="bottom"不起作用问题

    布局layout时, 发现设置了android:layout_gravity="bottom"后view并没有底对齐, 查了下, 原来如下: 对于 LinearLayout 当 a ...

  4. 一种针对虚拟机的应用软件License认证方法

    由于虚拟机的硬件信息可以随意修改,使得虚拟机可能具有相同的硬件信息,在传统的应用软件License认证方式中会导致License认证漏洞.本专利提供了一种有效的解决方法. 文/王宏财 目 前,云计算的 ...

  5. Spring AOP 本质(4)

    这一主要看看Spring AOP是如何实现通知包围的.   Spring AOP包围通知在功能上和前置通知加后置通知类似,但还是有区别的:包围通知可以修改返回值,还可以阻止.替换目标方法的执行.   ...

  6. CSS3 新特性 开放字体格式WOFF

    疑问 上面这是虾米玩意?    \e806 是在自定义字体表中的字体位置.    好嘛 现在问题来了 WOFF里面是什么东西呢? 怎么才能看到? 用这个:FontCreatorPortable     ...

  7. 使用STS 创建spring配置文件

    1.创建一个bean文件 2.输入文件名applicationContext.xml 3.这里会自动显示模板文件 4.创建后,自动填充头不定义 到这里就可以发现,我们创建spring文件时,需要的配置 ...

  8. 黑马程序员 Java正则表达式,详解反斜线在Java中的作用

    ---------------------- ASP.Net+Android+IO开发S. .Net培训.期待与您交流! ---------------------- 在程序设计过程中,经常需要对获取 ...

  9. 第04章-VTK基础(4)

    [译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年,ISBN: 978-1-930934- ...

  10. fedora 20下安装vim的C++补全插件clang_complete

    1.安装clang yum install clang 2.安装clang_complete插件 git clone https://github.com/Rip-Rip/clang_complete ...