标签:
#include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> #include<queue> using namespace std; const int INF=0xfffffff; #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x) #define PI(x) printf("%d",x) typedef long long LL; const int MAXN=110; double lx[MAXN],ly[MAXN]; double mp[MAXN][MAXN]; int N; double ans; double C,R; double d[MAXN]; double getl(int i,int j){ double y=ly[j]-ly[i],x=lx[j]-lx[i]; return sqrt(x*x+y*y); } void work(){ ans=INF; for(int i=1;i<(1<<N);i++){ double temp=0; for(int k=0;k<N;k++)d[k]=INF; for(int j=0;j<N;j++){ if(i&(1<<j)){ temp+=C; for(int k=0;k<N;k++){ d[k]=min(d[k],R*mp[k][j]); } d[j]=0; // printf("%d ",j); } } //puts(""); for(int i=0;i<N;i++)temp+=d[i]; //for(int k=0;k<N;k++)printf("d[%d]=%.1lf ",k,d[k]);puts(""); ans=min(ans,temp); } printf("%.2f\n",ans); } int main(){ int T; SI(T); while(T--){ scanf("%d%lf%lf",&N,&C,&R); for(int i=0;i<N;i++){ scanf("%lf%lf",&lx[i],&ly[i]); } for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) mp[i][j]=mp[j][i]=getl(i,j); work(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5232340.html