Hdu2639bone Collector II (k-Large backpack)

Source: Internet
Author: User

Bone Collector IITime limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3780 Accepted Submission (s): 1947


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

Authorteddy
Source million Qin Guan end belongs to CHU test instructions on the back of v packaging of the K-major items include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace Std;
int a[10000],b[10000],c[10000],d[10000];
int dp[1000][1000];
int main ()
{
int m,i,j,v1,v2,k;
scanf ("%d", &m);
while (m--)
{
int n;
scanf ("%d%d%d", &n,&v1,&v2);
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
for (i=0;i<n;i++)
scanf ("%d", &b[i]);
Memset (Dp,0,sizeof (DP));
for (i=0;i<n;i++)
{
for (j=v1;j>=b[i];j--)//01 backpack
{
for (k=1;k<=v2;k++)//0~k large backpack to find out.
{
C[k]=dp[j-b[i]][k]+a[i];//c[k] refers to the backpack K large is the item taken.
D[k]=dp[j][k];//d[k] refers to the size of the backpack K large the item is not taken
}
c[k]=d[k]=-1;//done with the end.
int x, y, Z;
X=Y=Z=1;//X is control DP, Y is control C, Z control D.
while (x<=v2&& (c[y]!=-1| | D[Z]!=-1)//start sorting C and D to DP
{
if (C[y]>d[z])
{
Dp[j][x]=c[y];
y++;
}
Else
{
DP[J][X]=D[Z];
z++;
}
if (dp[j][x]!=dp[j][x-1])//Since two K-large does not have an equal
x + +;
}
}
}
printf ("%d\n", Dp[v1][v2]);
}


return 0;
}

Hdu2639bone Collector II (k-Large backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.