HDU 2639 Bone Collector II

Source: Internet
Author: User

Bone Collector IITime Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 2089 Accepted Submission (s): 1097


Problem DescriptionThe 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 = 1, 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.
InputThe first line contain a integer T, the number of instances.
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.

OutputOne 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

Authorteddy
Source million Qin Guan Chu
Recommendteddy | We have carefully selected several similar problems for you: 2602 2159 1203 2955 Solution: Find the k solution of the backpack, you only need to add one-dimensional dp [j] [k] to the status, which indicates the k-large solution for loading the first I item into a backpack with a capacity of j, use two arrays to save the first k large scheme of the two options, and then combine them to get the final result.
#include 
 
  using namespace std;bool cmp(int a,int b){return a>b;}int main(){int i,j,t,n,v,k,p;int cost[105],val[105],dp[1005][35],a[35],b[35];//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);scanf("%d",&t);while(t--){memset(dp,0,sizeof(dp));scanf("%d%d%d",&n,&v,&k);for(i=0;i
  
   =cost[i];j--){for(p=0;p
   
    b[t])dp[j][p]=a[s++];elsedp[j][p]=b[t++];if(dp[j][p]!=dp[j][p-1])p++;}}printf("%d\n",dp[v][k-1]);}return 0;}
   
  
 



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.