题目描述
纸牌三角形
思路分析
全排列+特殊去重
ans/6
代码实现
package com.atguigu.TEST;class Main{public static int[] a={1,2,3,4,5,6,7,8,9};public static int ans;public static void f(int k){if(k==9){int x1 = a[0] + a[1] + a[2] + a[3];int x2 = a[3] + a[4] + a[5] + a[6];int x3 = a[6] + a[7] + a[8] + a[0];if (x1 == x2 && x2 == x3)ans++;}for (int i = k; i < 9; i++) {int temp=a[i];a[i]=a[k];a[k]=temp;f(k+1);temp=a[i];a[i]=a[k];a[k]=temp;}}public static void main(String[] args) {f(0);System.out.println(ans/6);}
}
答案
144