public class HuiTest {
static int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
static int count;
// 邻里交换法是让不确定的数与确定的数交换
public static void f(int a[], int step) {
// 最后一个
if (step == a.length - 1) {
if (a[1] + a[2] + a[3] + a[4] == a[4] + a[5] + a[6] + a[7] && a[1] + a[2] + a[3] + a[4] == a[7] + a[8] + a[9] + a[1]) {
count++;
}
return;
}
for (int i = step; i < a.length; i++) {
int temp = a[i];
a[i] = a[step];
a[step] = temp;
f(a, step + 1); // 递归调用
// 还原数组
temp = a[i];
a[i] = a[step];
a[step] = temp;
}
}
public static void main(String[] args) {
f(a, 0);
System.out.println(count / 6);
}
}