HDU4281 Judges & amp; #39; response (State compression + 01 backpack + group backpack) Classic

Source: Internet
Author: User

HDU4281 Judges & #39; response (State compression + 01 backpack + group backpack) Classic
Judges 'responseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 565 Accepted Submission (s): 308


Problem Description The contest is running and the judges is busy watching the progress of the contest. suddenly, N-1 (N <= 16) contestants hand up their hand at the same time. the judges shocould go to answer the contestants 'Question one by one. the judges already foresee that answering contest I's question wowould cost Ci minutes. in order to serve all the contestant, each judges is assigned to serve some subset of the contestants. as the judges have limited patience, each one of them can serve the contestants for no more than M minutes.
You are asked to solve two problems:
1. At least how should judges shoshould be sent so that they can serve all the contestants? (Because the judges have limited patience, each one of them cannot serve too using contestants .)
2. If there are infinite number of judges, how to assign the route for each judge so that the sum of their walking time is minimized? Each contestant I is reside in place (xi, yi), the judges are in place (x1, y1). Assuming the walking speed of the judge is 1.

Input There are several test cases, Each case begin with two integer N, M (with the meaning in the above context, 2 <= N <= 16, 0 <= M <= 100000 ).
Then N lines follow and line I will contain two numbers x, y (0 <= x, y <= 1000), indicating the coordinate of place I.
Then another N lines follow and line I will contain numbers Ci (0 <= Ci <= 1000), indicating the time to solve contestant I's question. c1 will 0 as place 1 is for the judges.
  
The distance between place I and place j is defined as ceil (sqrt (xi-xj) ^ 2 + (yi-yj) ^ 2 )). (ceil means rounding the number up, e.g. ceil (4.1) = 5)

Output For each case, output two numbers. The first is the minimum number of judges for question 1. The second is the minimum sum of walking time for question 2.
If it's impossible to serve all the contestants, please output-1-1 instead.

Sample Input

3 30 00 30 10123 20 00 30 10123 10 00 30 1012  16 3530 4037 5249 4952 6431 6252 3342 4152 4157 5862 4242 5727 6843 6758 4858 2737 69019301623113115288871461911

Sample Output
1 62 8-1 -18 467

Source2012 ACM/ICPC Asia Regional Tianjin Online question: n points are given. The first point is the location of the referee, And the other n-1 points are the tasks that need to be completed by the referee, the total time for each referee to complete the task cannot exceed M (excluding the walking time). Each point has a coordinate and the time for completing the task, the time taken by the referee from one point to another is the distance between two points. (1) The minimum number of referees required to complete all tasks. (2) If there are countless referees, the minimum time required to complete all tasks is the sum of time. (Each referee must eventually return to the original position and use the condition (1) to obtain the number of referees ).
Analysis: because the total time for each referee to perform the task cannot exceed M, use state compression to find the task that the referee can complete and record it, then complete the (1) it's easy to ask. DP directly. To answer question (2), first calculate the status of the task completed by a referee (a referee must complete this status) the minimum time (excluding the time when the original location is returned), and then the minimum time when each status returns to the original location with a certain vertex as the ending point. Use a grouping backpack to find the minimum time it takes for the I referee to complete the task State s. Finally, the result is obtained.
# Include
 
  
# Include
  
   
Const int N = 1 <16; const int inf = 0 xfffffff; int dpk [N], dps [N], state [N], k, OK [N]; int map [16] [16], routeDist [N] [16], dpks [16] [N]; double x [16], y [16]; int n, m, c [16]; // ------------ initialize ------------- void init () {// obtain the distance between two points for (int I = 0; I
   
    
B? B: a;} void countRouteDist () {int tn = n-1; for (int I = 1; I <(1 <
    
     
State [j]; s --) // status of each task if (s | state [j]) = s & dpks [I-1] [s ^ state [j]! = Inf) dpks [I] [s] = min (dpks [I] [s], dpks [I-1] [s ^ state [j] + dps [state [j]);} void zeroOne () {int tn = n-1; for (int I = 0; I
     
      
= State [I]; s --) if (s | state [I]) = s) {if (dpk [s]> dpk [s ^ state [I] + 1) dpk [s] = dpk [s ^ state [I] + 1 ;}} int main () {int flag, MIN; while (scanf ("% d", & n, & M)> 0) {flag = 0; scanf ("% lf", & x [n-1], & y [n-1]); // the location of the referee for (int I = 0; I
      
        M) flag = 1;} if (flag) {printf ("-1-1 \ n"); continue;} init (); zeroOne (); countRouteDist (); n --; MIN = inf; for (int I = dpk [(1 <
       
        

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.