HDU3602 2012 "DP"

Source: Internet
Author: User

2012

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 647 Accepted Submission (s): 246


Problem Descriptionas We know,2012 is coming,and the presidents of many countries has planned to board the airships. We also know that every president I'll bring a[i] bodyguards to make sure his safe,and he'll pay b[i] billion dollars To U.N. We also know that some countries is more powerful than others,so if we had chose some countries to board the Ship,we mus T Make the powerful countries board first, and make sure this bodyguards stay the same ship with his president.
NOW,U.N has m ships. And every ship can only contain k people. So cannot on the people,but the U.N want to make more mongey. Make the U.n,then the U.N would give Lazy Yangyang a chance to survive when was coming.
Lazy Yangyang want to being safe so, he can inherit the job of ACM for the New World. The dream come true,the acmers of the world is solving the problem for Lady Yy,and is one of the them ...

Inputin The first line there was an integer T, indicates the number of test cases. (T <= 10)
In each case, the first line contains three integers n,m and K. (0 <m<=n <=100,0<k<100000)
Then n line,every line have integers a[i], b[i], (0<=a[i]<100000,0<=b[i]<100) representing the bodyguards an D dollars, ordered by their power,the first country are the most powerful country.

Outputmost money, that U.N can get.

Sample Input14 2 40060 1180 1180 1260 1

Sample OUTPUT3 HintYou can choose country 1 3 4,make the 1 3 on ship 1,and make country 4 at ship 2;but do cannot make 1 4 at ship 1, and Co Untry 2 3 at Ship 2,because 2 are more powerful than country 4, so 2 should sit behind country 1!

Authoralpc72

Source2010 acm-icpc multi-university Training Contest (+)--host by Nudt The main idea: there are N presidents every president with A[i] a bodyguard to be on the M spacecraft each ship can be a K-man elect some president of the boat Excellent First-class high in front must be lower than priority before the President must bring all the bodyguards to the boat to pay b[i] The maximum value of the fee is how much analysis: Dp[i][j] represents the first I personal income is J minimum number of passengers then DP[I][J + b[i]] = min (dp[i][j + b[ I]], come up a[i] personal final number of passengers) code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intMAXN = the;7 Const intMAXM =10005;8 intA[MAXN], B[MAXN];9 intDP[MAXN][MAXM];Ten  One intMain () { A     intT; -     intN, M, K; -scanf"%d",&t); the      while(t--) { -scanf" %d%d%d", &n, &m, &k); -         intMax =0; -         intINF = m *K; +          for(inti =1; I <= N; i++) { -scanf"%d%d", &a[i], &b[i]); +a[i]++; AMax + =B[i]; at         } -Memset (DP,0x3f,sizeof(DP)); -dp[0][0] =0; -          for(inti =1; I <= N; i++) { -             if(A[i] > K)Continue; -              for(intj =0; J <= Max; J + +) { inDp[i][j] = min (dp[i][j], dp[i-1][j]); -                 if(Dp[i-1][J] <=INF) { to                     intPnum = Dp[i-1][j]; +                     intAnum =A[i]; -                     intAns =0; the                     if(pnum% k = =0|| (K-(pnum% k)) >=anum) { *Ans = pnum +Anum; $}Else {Panax NotoginsengAns = (pnum/k +1) * k +Anum; -                     } the                     if(Ans <= m *k) { +Dp[i][j + b[i]] = min (dp[i][j +B[i]], ans); A                     } the                 }  +             } -         } $         intAns =0; $          for(intj = Max; J >=0; j--) { -             if(Dp[n][j] <=INF) { -Ans =J; the                  Break; -             }Wuyi         } theprintf"%d\n", ans); -     } Wu     return 0; - } About  $  -         
View Code

HDU3602 2012 "DP"

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.