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 DescriptionThe Title of this problem be familiar,isn ' t it?yeah,if you had took part in the ' Rookie Cup ' competitio N,you must has seem this title. If you haven ' t seen it before,it doesn ' t matter,i would give you a link:
The link:http://acm.hdu.edu.cn/showproblem.php?pid=2602
Today We is not desiring the maximum value of bones,but the k-th maximum value of the bones. NOTICE That,we considerate and ways that get the same value of bones is the same. That means,it'll be a strictly decreasing sequence from the 1st maximum, 2nd maximum. To the k-th maximum.
If the total number of different values are less than k,just ouput 0.
Inputthe first line contain a integer T, the number of cases.
Followed by T cases, each case three lines, the first line contain both integer n, v, K (n <=, v <=, K & lt;=) 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 for each bone.
Outputone integer per line representing the k-th maximum of the total value (this number would be less than 2 to).
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 Output1220 records the K-solution of each State;
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 intdp[1002][ +];7 intval[102],vol[102];8 intn,v,k;9 inta[ +],b[ +];Ten intMain () One { AFreopen ("In.txt","R", stdin); - inti,j,k; - intx, y, z the intT; -scanf"%d",&T); - while(t--) - { +scanf"%d%d%d",&n,&v,&K); - for(i=1; i<=n;i++) +scanf"%d",&val[i]); A for(i=1; i<=n;i++) atscanf"%d",&vol[i]); -Memset (DP,0,sizeof(DP)); - for(i=1; i<=n;i++) - { - for(j=v;j>=vol[i];j--) - { in for(k=1; k<=k;k++)//record K-Optimal solutions for each State - { toa[k]=Dp[j][k]; +b[k]=dp[j-vol[i]][k]+Val[i]; - } thea[k]=b[k]=-1;//the stored content has been sorted from small to large, and then merged into the DP array . *x=y=z=1; $ while(z<=k&& (a[x]!=-1|| b[y]!=-1))Panax Notoginseng { - if(a[x]>B[y]) the { +dp[j][z]=A[x]; AX + +; the } + Else - { $dp[j][z]=B[y]; $y++; - } - if(dp[j][z-1]!=Dp[j][z]) thez++; - }Wuyi } the } -printf"%d\n", Dp[v][k]); Wu } - return 0; About}
Bone Collector II (HDU 2639 DP)