显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,x[25],y[25],f[1<<24],fz[25],ans,sum,jj;
int main(){
freopen("lenepack.in","r",stdin);
freopen("lenepack.out","w",stdout);
scanf("%d%d",&x[0],&y[0]);
scanf("%d",&n);
fz[0]=1;for(int i=1;i<=n;i++)fz[i]=fz[i-1]*2;
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
x[i]-=x[0],y[i]-=y[0];
sum+=x[i]*x[i]*2+y[i]*y[i]*2;
}
ans=sum;
for(int i=0;i<fz[n];i++){
for(int j=1;j<=n;j++){
if((i>>j-1)&1)continue;
if(j!=n)for(int k=j+1;k<=n;k++){
if((i>>k-1)&1)continue;jj=x[j]*x[k]+y[j]*y[k];
if(jj<=0)continue;
f[i+fz[j-1]+fz[k-1]]=max(f[i+fz[j-1]+fz[k-1]],f[i]+jj);
}
break;
}
ans=min(ans,sum-2*f[i]);
}
printf("%d\n",ans);
return 0;
}