Qiuqiqiu  
不管道路多么崎岖坎坷,我永远不停下追逐梦想的脚步!

http://acm.hdu.edu.cn/showproblem.php?pid=3920

View Code
 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 
 7 double d[1100000];
 8 bool vis[1100000];
 9 int n;
10 struct point
11 {
12     double x,y;
13     void input()
14     {
15         scanf("%lf%lf",&x,&y);
16     }
17 };
18 point me,e[25];
19 double dis(point a,point b)
20 {
21     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
22 }
23 double dp(int s)
24 {
25     if(vis[s]) return d[s];
26     vis[s]=true;
27     double ans=1e20;
28     int i;
29     for(i=0;i<n;i++)
30         if(((s>>i)&1)==1) break;
31     for(int j=i+1;j<n;j++)
32         if(((s>>j)&1)==1)
33         {
34             double t=dp(s^(1<<i)^(1<<j));
35             t+=min(dis(me,e[i]),dis(me,e[j]))+dis(e[i],e[j]);
36             if(t<ans) ans=t;
37         }
38     return d[s]=ans;
39 }
40 int main()
41 {
42     int T,C=0;
43     scanf("%d",&T);
44     while(T--)
45     {
46         memset(d,0,sizeof(d));
47         memset(vis,0,sizeof(vis));
48         vis[0]=true;
49         me.input();
50         scanf("%d",&n);
51         n*=2;
52         for(int i=0;i<n;i++) e[i].input();
53         double ans=dp((1<<n)-1);
54         printf("Case #%d: %.2lf\n",++C,ans);
55     }
56     return 0;
57 }

 

posted on 2012-07-09 20:23  Qiuqiqiu  阅读(146)  评论(0编辑  收藏  举报