Codeforces Gym 100610 problem K. Kitchen Robot pressure DP

Source: Internet
Author: User
Tags integer numbers

Problem K. Kitchen Robot

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://codeforces.com/gym/100610
Description

Robots is becoming more and more popular. They is used nowadays not only in manufacturing plants, but also at home. One programmer with he friends decided to create their own home robot. As know most programmers like to drink beer when they gather together for a party. After the party there is a lot of empty bottles left on the table. So, it is decided to program robot to collect empty bottles from the table. The table is a rectangle with the length L and width W. Robot starts at the point (XR, yr) and n bottles be located at PO INTs (xi, yi) for i = 1, 2, ..., N. To collect a bottle robot must moves to the point where the bottle are located, take it, and then bring-to-some point on the Border of the table to dispose it. Robot can hold only one bottle at the moment and for simplicity in the control program it's allowed to release bottle onl Y at the border of the table. Bottle Bottle Robot l W x y can assume that sizes of Robot and bottles is negligibly small (Robot and bottles is points), so the robot holding a bottle was allowed to move through the point where another bottle is Locat Ed. One of the subroutines of the robot control program is the route planning. You is to write the program to determine the minimal length of robot route needed to collect all the bottles from the tab Le.

Input

The first line of the input file contains the numbers w and l-the width and the length of the table (2≤w, l≤ The second line of the input contains a integer number n-the number of bottles on the table (1≤N≤18). Each of the following n lines contains both integer numbers XI and yi-coordinates of the i-th bottle (0 < XI < W; 0 < Yi < L). No. Bottles is located at the same point. The last line of the input file contains the numbers XR and yr-coordinates of the robot ' s initial position (0 &L T XR < W; 0 < yr < L). Robot is isn't located at the same point with a bottle.

Output

Output the length of the shortest route of the robot. Your answer should is accurate within an absolute error of 10−6.

Sample Input

3 4 2 1 1 2 3 2 1

Sample Output

5.60555127546399

HINT

Test instructions

The data range has already told us that this is the dp......% pressure

Exercises

Just like the pressure DP.

Code:

#pragmaComment (linker, "/stack:1024000000,1024000000")#include<iostream>#include<cstdio>#include<vector>#include<cmath>#include<cstring>using namespacestd;Const intMAXN = -+2;structbottle{Doublex, y;};intW, l, N, ed;DoubleStx,sty;bottle P[MAXN];Doubledp[ +][(1<< -)+5];BOOLarrived[ +][(1<< -)+5];inlineDoubleDIS (DoubleX1,DoubleY1,DoubleX2,Doubley2) {    returnsqrt ((x2-x1) * (x2-x1) + (y2-y1) * (Y2-y1));}DoubleDfsintXinty) {    if(Arrived[x][y])returnDp[x][y]; Arrived[x][y]=true; Double& ans = dp[x][y] =1e233; intSZ =0; if(x = =N) { for(inti =0; I < n; + + i) ans = min (ans, dfs (i, y) +DIS (STX,STY,P[I].X,P[I].Y)); returnans; }     for(inti =0; I < n; + + i)if((y>>i) &1) sz++; if(SZ = =1)returnans = min (min (p[x].x, (Double) w-p[x].x), Min (P[x].y, (Double) (L-P[X].Y));//one last bottle .    Else    {        DoubleX1 =p[x].x; DoubleY1 =p[x].y;  for(inti =0; I < n; ++i)if((y >> i) &1)            {                if(i = = x)Continue; Doublex2 =p[i].x; Doubley2 =p[i].y; Doubleres =1e233; Res= Min (res, DIS (-x1,y1,x2,y2)); Res= Min (res, DIS (x1,-y1,x2,y2)); Res= Min (res, DIS (2.0*w-x1, y1, x2, y2)); Res= Min (res, DIS (x1,2.0*l-y1,x2,y2)); Ans= min (ans, dfs (i, Y & (~ (1&LT;&LT;X)) +res); }    }    returnans;}intMainintargcChar*argv[]) {Freopen ("kitchen.in","R", stdin); Freopen ("Kitchen.out","W", stdout); scanf ("%d%d%d",&w,&l,&N);  for(inti =0; I < n; + + i) scanf ("%LF%LF", &p[i].x, &p[i].y); scanf ("%LF%LF",&stx,&sty); Memset (arrived,false,sizeof(arrived)); Ed=1<<N; printf ("%.14lf\n", DFS (n,ed-1)); return 0;}

Codeforces Gym 100610 problem K. Kitchen Robot pressure 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.