HDU2659(01背包加元素)
来源:互联网 发布:drupal建站 编辑:程序博客网 时间:2024/06/06 03:44
Bone Collector II
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4991 Accepted Submission(s): 2618
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.
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.
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
35 10 21 2 3 4 55 4 3 2 15 10 121 2 3 4 55 4 3 2 15 10 161 2 3 4 55 4 3 2 1
Sample Output
1220
Author
teddy
Source
百万秦关终属楚
#include<cstdio>#include<iostream>#include<cstring>#include<string.h>using namespace std;const int MAXN=105;const int MAXV=1005;int t,n,V,k;int c[MAXN],v[MAXN],dp[MAXV][MAXN];int a[MAXN],b[MAXN]; int main(){scanf("%d",&t);while(t--){scanf("%d%d%d",&n,&V,&k);memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)scanf("%d",&v[i]);for(int i=1;i<=n;i++)scanf("%d",&c[i]);for(int i=1;i<=n;i++)for(int j=V;j>=c[i];j--){int l;for(l=1;l<=k;l++){a[l]=dp[j][l];b[l]=dp[j-c[i]][l]+v[i];}int p=1,p1=1,p2=1;a[l]=-1;b[l]=-1;while(p<=k&&(a[p1]!=-1||a[p2]!=-1)){if(a[p1]>b[p2]){dp[j][p]=a[p1];p1++;} else{dp[j][p]=b[p2];p2++;}if(dp[j][p]!=dp[j][p-1])//一样大的时候 {p++;}}}printf("%d\n",dp[V][k]);}}
阅读全文
0 0
- HDU2659(01背包加元素)
- HDU3339 最短路加01背包
- 01背包 加 贪心 HDOJ2546饭卡
- hdu5188 加限制的01背包问题
- luogu1941【2014提高】飞扬的小鸟(完全背包加01背包)
- HDU3244----二分法加完全背包
- 背包问题加记录路径
- HDU5501贪心加DP零一背包
- 【背包专题】01背包
- 01背包,完全背包
- 01背包 完全背包
- 01背包/完全背包
- 01背包,完全背包
- 背包问题---01背包
- 背包入门--01背包
- 【背包专题】01背包
- 01背包,完全背包
- 清单文件AndroidManifest文件可加元素
- 2017 Multi-University Training Contest 3 1005
- 技能冷却可以使用两张图片,改变一张图片的透明度
- Git 学习笔记(简介、安装、添加提交文件、查看状态及更改信息)
- JavaScript 中学习数据结构与算法
- Maven 依赖冲突
- HDU2659(01背包加元素)
- 正则中$1、$2的应用--日期格式化
- 常见算法实现
- linux内核API每天来一发(vfs)
- vs在编写c++时报错找不到标识符
- 刷题——hdu 6090 Rikka with Graph
- 语音识别的痛点在哪,从交互到精准识别如何做?
- 简单的文件下载
- AngularJS内幕详解之 Scope