杭电-2639Bone Collector II
来源:互联网 发布:北京行知实验小学 编辑:程序博客网 时间:2024/06/05 06:33
Bone Collector II
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3208 Accepted Submission(s): 1663
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
01背包的变形体,这次不是让背包的容量最大了,是要求出给定的第K大
我不是很理解,大概意思就是说,把每一种容量的背包的前K种方法都写出来!
下面是我借鉴的别人的解释:
题意:给出一行价值,一行体积,让你在v体积的范围内找出第k大的值.......(注意,不要 和它的第一题混起来,它第一行是价值,再是体积)
思路:首先dp[i][j]代表的是在体积为i的时候第j优解为dp[i][j]......那么,我们就可以这样思考,i对应体积,那么如果只是一维的dp[i],代表的应该是体积为i时的最大值,那么同理,dp[i][1]代表的是体积为i时的最大值,那么我们就可以退出两种动态,dp[i][m],dp[i-s[i][0]][m]+s[i][1].....然后把这两种状态开个两个数组分别保存起来,再合并出体积为i时的前k优解......依次后推,直到dp[v][k].......
下面代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int f[1010][33];int main(){int N,i,j,v,n,k,val[110],vol[110];scanf("%d",&N);while(N--){scanf("%d%d%d",&n,&v,&k);for(i=0;i<n;i++)scanf("%d",&val[i]);for(i=0;i<n;i++)scanf("%d",&vol[i]);memset(f,0,sizeof(f));int a[50],b[50],kk;for(i=0;i<n;i++)for(j=v;j>=vol[i];j--){for(kk=0;kk<k;kk++){a[kk]=f[j-vol[i]][kk]+val[i];b[kk]=f[j][kk];}a[k]=b[k]=-1;int x=0,y=0,z=0;while(z<k&&(a[x]!=-1||b[y]!=-1)){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++;}}printf("%d\n",f[v][k-1]);}return 0;}
0 0
- 杭电-2639Bone Collector II
- 杭电2639 Bone Collector II(01背包第K优解)
- 杭电2602-Bone Collector
- 杭电 2602 Bone Collector
- 杭电 2602 Bone Collector
- 杭电-2602Bone Collector
- 【杭电】[2602]Bone Collector
- hdu 2639 Bone Collector II
- HDOJ 2639 Bone Collector II
- Hdu 2639 Bone Collector II
- hdu 2639 Bone Collector II
- hdu 2639 Bone Collector II
- HDU 2639 Bone Collector II
- HDU-2639-Bone Collector II
- hdu 2639 Bone Collector II
- HDU 2639 Bone Collector II
- hdu 2639 Bone Collector II
- hdu 2639 Bone Collector II
- 【已解决】Genymotion, “Unable to load VirtualBox engine”
- codeforces585D. Lizard Era: Beginning
- cf 18a Triangle
- iOS: 通过addChildViewController实现 Segment 下的 View 的切换
- 硬盘和显卡的访问与控制(一)——《x86汇编语言:从实模式到保护模式》读书笔记01
- 杭电-2639Bone Collector II
- ASCII排序 nyoj4
- 需求分析过程
- sql 存储过程 循环
- R12.1.3 应用克隆过程中autocfg脚本报错
- 日语五十音图
- 手机网站字号自适应
- jre运行报Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
- Python + Requests + Unittest接口自动化测试