A,2,3,4,5,6,7,8,9 共9张纸牌排成一个正三角形(A按1计算)。要求每个边的和相等。
下图就是一种排法(如有对齐问题,参看p1.png)。
A
9 6
4 8
3 7 5 2
这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
下图就是一种排法(如有对齐问题,参看p1.png)。
A
9 6
4 8
3 7 5 2
这样的排法可能会有很多。
如果考虑旋转、镜像后相同的算同一种,一共有多少种不同的排法呢?
请你计算并提交该数字。
public class Solution {
static int[] s = new int[9];
static int[] flag = new int[9];
static int count = 0;
void cardTriangle(int num) {
if (num == 9) {
if (s[0] + s[1] + s[2] + s[3] == s[3] + s[4] + s[5] + s[6]
&& s[3] + s[4] + s[5] + s[6] == s[6] + s[7] + s[8] + s[0]) {
count++;
}
}
for (int i = 0; i < 9; i++) {
if (flag[i] == 0) {
flag[i] = 1;
s[num] = i + 1;
cardTriangle(num + 1);
flag[i] = 0;
}
}
}
public static void main(String[] args) {
Solution solution = new Solution();
solution.cardTriangle(0);
System.out.println(count/6);
}
}