HDU - 2639 Bone Collector II

dp之难,难于上青天。

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 2 31).
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

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#define N 1010
#define maxn 2111
const long long INF = 1e8;
using namespace std;
int n,vol,k;
int dp[1005][35],value[105],cost[105],A[35],B[35];void kth_ZeroOnePack(){memset(dp,0,sizeof(dp));int i,j,kk,a,b,c;for(i=1;i<=n;i++){for(j=vol;j>=cost[i];j--){for(kk=1;kk<=k;kk++){A[kk]=dp[j-cost[i]][kk]+value[i];B[kk]=dp[j][kk];}A[kk]=B[kk]=-1;a=b=c=1;while(c<=k&&(A[a]!=-1||B[b]!=-1)){if(A[a]>B[b]){dp[j][c]=A[a];a++;}else{dp[j][c]=B[b];b++;}if(dp[j][c]!=dp[j][c-1]){c++;}}}}printf("%d\n",dp[vol][k]);
}
int main()
{int t,i,j;scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&vol,&k);for(i=1;i<=n;i++){scanf("%d",&value[i]);}for(i=1;i<=n;i++){scanf("%d",&cost[i]);}kth_ZeroOnePack();}return 0;
}

HDU - 2639 Bone Collector II相关推荐

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

  2. HDU 2639 Bone Collector II(01背包-第K优决策)

    Description 给出n件物品的价值和体积,问在总体积不超过v时的第k大价值 Input 第一行为用例组数T,每组用例第一行为三个整数n,v和k,第二行n个整数表示这n件物品的价值,第三行n个整 ...

  3. HDOJ 2639 Bone Collector II (背包)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2639 第K优解问题 其基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序 ...

  4. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  5. HDU 2602 Bone Collector DP(01背包)

    Bone Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Desc ...

  6. hdu 2602 Bone Collector 01背包

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

  7. 【HDU - 2639】Bone Collector II (第K大背包,dp,STLset)

    题干: The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup ...

  8. Bone Collector II

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 The title of this problem is familiar,isn't it?yeah,i ...

  9. hdu 2602 Bone Collector

    终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...

最新文章

  1. SAP MM 自定义条件类型出现在采购信息记录的'条件'界面里 ?
  2. 成功解决on line , but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
  3. super() 函数??
  4. 接受数据,table列表,外加判断
  5. 利用RTL2832u电视棒芯片追踪民航飞机轨迹
  6. matlab 计算指北角,用MATLAB如何计算出矩形区域内的最大值?
  7. classdefnotfound本地不报错_四种解决Nginx出现403 forbidden 报错的方法
  8. 评测网站的十个指标!
  9. C语言单片机笔试题,c语言面试题集(单片机
  10. 论文相关------如何在论文写作中使用拉丁文简写
  11. Python抓取行政区域划分存入MySQL数据库
  12. MySQL over函数的用法
  13. libx264 编码参数调整--流媒体
  14. 【懒人必备神器】教你用Python做一个自动抽奖程序啦~
  15. 【 MySQL1064错误代码】
  16. 密码学总结(一) 数学常识
  17. 嵌入式linux,增加串口登陆密码
  18. Android 微信h5支付
  19. 【原创】解决windows命令行运行程序必须输入.exe后缀的问题
  20. 什么是GIS(地理信息系统)

热门文章

  1. RocketMQ 常见面试问题
  2. 短视频如何赚钱 短视频自媒体实操经验分享+真实
  3. 关于嵌入式容器技术的调研
  4. 运动什么蓝牙耳机好用?
  5. touchend在iphone 6s中不生效
  6. BUUCTF Crypto
  7. 计算机网络智能化在铁路通信的发展,关于计算机铁路通信技术的研究
  8. 修改iphone微博的GPS位置(iOS6.1.2)
  9. bodipy荧光染料BDP 581/591 NHS ester/琥珀酰亚胺活化酯
  10. idea断点突然变灰色及debugger模式缓慢