HDU 2639 Bone Collector II

Source: Internet
Author: User

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
122

0

For the Big K. Start thinking is to add a big to small to find the value of K, why not

Add one-dimensional value that represents the K-large when the volume is J. Use two arrays to store the two states in addition or not, and merge with the idea of merging.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace    STD; #define INF 0x3f3f3f3fint n,v,k;int va[105],vo[105],dp[1010][50];int a[50],b[50];int main () {int t,i,j,x,y,z,r;    scanf ("%d", &t);        while (t--) {scanf ("%d%d%d", &n,&v,&k);        for (i=0;i<n;i++) scanf ("%d", &va[i]);        for (i=0;i<n;i++) scanf ("%d", &vo[i]);        memset (dp,0,sizeof DP);                    for (i=0;i<n;i++) for (j=v;j>=vo[i];j--) {for (r=1;r<=k;r++) {                    A[r]=dp[j-vo[i]][r]+va[i];                B[R]=DP[J][R];                } a[r]=-1,b[r]=-1;                X=y=z=1; while (z<=k&& (a[x]!=-1| |                    B[y]!=-1) {if (A[x]>b[y]) dp[j][z]=a[x++];                    else dp[j][z]=b[y++];             if (Dp[j][z]!=dp[j][z-1])       z++;    }} printf ("%d\n", Dp[v][k]); } return 0;}


HDU 2639 Bone Collector II

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.