标题:五星填数
如【图1.png】的五星图案节点填上数字:1~12,除去7和11。
要求每条直线上数字和相等。
如图就是恰当的填法。
请你利用计算机搜索所有可能的填法有多少种。
注意:旋转或镜像后相同的算同一种填法。
请提交表示方案数目的整数,不要填写任何其它内容。
/**
* Created by m1786 on 2017/3/18.
*/
public class 五星填数 {
static int []a=new int[]{1,2,3,4,5,6,8,9,10,12};
static int count=0;
public static void main(String args[]){
dfs(0);
System.out.println(count/10);//去掉旋转和对称 5*2
}
static boolean check(){
int temp = a[0] + a[5] + a[6] + a[2];
if(temp != a[2] + a[7] + a[8] + a[4])
return false;
if(temp != a[4] + a[9] + a[5] + a[1])
return false;
if(temp != a[1] + a[6] + a[7] + a[3])
return false;
if(temp != a[3] + a[8] + a[9] + a[0])
return false;
return true;
}
static void dfs(int n){
if(n==10){
if(check())
count++;
}
for(int k=n;k<10;k++){
int temp;
temp=a[k];a[k]=a[n];a[n]=temp;
dfs(n+1);
temp=a[k];a[k]=a[n];a[n]=temp;
}
}
}