void Circle::Backtrack(int t)
{
if (t>n) Compute();
else
for (int j = t; j <= n; j++) {
Swap(r[t], r[j]);
float centerx=Center(t);
if (centerx+r[t]+r[1]<min)
{//下界约束
x[t]=centerx;
Backtrack(t+1);}
Swap(r[t], r[j]);}
}
float Circle::Center(int t)
{// 计算当前所选择圆的圆心横坐标
float temp=0;
for (int j=1;j<t;j++) {
float valuex=x[j]+2.0*sqrt(r[t]*r[j]);
if (valuex>temp) temp=valuex;
}
return temp;
}
void Circle::Compute(void)
{// 计算当前圆排列的长度
float low=0,
high=0;
for (int i=1;i<=n;i++) {
if (x[i]-r[i]<low) low=x[i]-r[i];
if (x[i]+r[i]>high) high=x[i]+r[i];
}
if (high-low<min) min=high-low;
}