博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU2639Bone Collector II[01背包第k优值]
阅读量:7251 次
发布时间:2019-06-29

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

Bone Collector II

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4229    Accepted Submission(s): 2205

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 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
 
Author
teddy

每个状态保存1到k优值,转移时给f[j][]和f[j-v][]+w二路归并一下就好了
复杂度O(nvk)
注意本题是严格递减
 
////  main.cpp//  hdu2639////  Created by Candy on 9/22/16.//  Copyright © 2016 Candy. All rights reserved.//#include
#include
#include
#include
#include
using namespace std;const int N=105,V=1005,K=35,INF=1e9+5;int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){
if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f;}int T,n,m,k,w[N],v[N];int f[V][K],a[K],b[K];void dp(){ memset(f,0,sizeof(f)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) for(int j=m;j>=v[i];j--){ for(int z=1;z<=k;z++) {a[z]=f[j][z];b[z]=f[j-v[i]][z]+w[i];} int x=1,y=1,z=1; while(z<=k&&(x<=k||y<=k)){ if(a[x]>=b[y]) f[j][z]=a[x++]; else f[j][z]=b[y++]; if(f[j][z]!=f[j][z-1]) z++; } }}int main(int argc, const char * argv[]) { T=read(); while(T--){ n=read();m=read();k=read(); for(int i=1;i<=n;i++) w[i]=read(); for(int i=1;i<=n;i++) v[i]=read(); dp(); printf("%d\n",f[m][k]); } return 0;}

 

转载地址:http://oeqbm.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
金山快盘开发(六)
查看>>
迅为三星Exynos嵌入式开发平台超强GPS模块
查看>>
C链表1-产生
查看>>
2014-07-04--vim相关知识
查看>>
sync logins from ASE 12.5.4 to ASE 15.5
查看>>
一个类似fork×××的效果
查看>>
Animation 动画的相关运用
查看>>
开源IDE LightTable的使用
查看>>
Hyper-V在线扩展磁盘空间总结
查看>>
Microsoft File Transfer Manager
查看>>
Hyper-V 3.0 - 存储迁移(简单)
查看>>
CentOS 7 Docker方式安装 PHP,Mysql,phpmyadmin 过程记录
查看>>
项目质量管理重点
查看>>
红冒系列-Systemctl命令详解说明
查看>>
Exchange2010开启outlook anywhere
查看>>
Linux who 命令 – 显示系统登录者
查看>>
(13)Powershell中的比较运算符与位运算符
查看>>
linux双网卡策略路由测试
查看>>
运维角度浅谈MySQL数据库优化
查看>>