算出来是389112
条件:
- 一共有9个点
- 至少经过4个点
- 每个点不能重复经过
- 直线上的中间点不能跳过
C++代码
/*
0 1 2
3 4 5
6 7 8
*/
#include<cstdio>
#include<algorithm>
using namespace std;
bool check(int a, int b, int state) {
if (a > b) swap(a, b);
if (a + 6 == b and !(state >> a + 3 & 1)) return false;
if (a / 3 == b / 3 and a + 2 == b and !(state >> a + 1 & 1)) return false;
if (a == 0 and b == 8 and !(state >> 4 & 1)) return false;
if (a == 2 and b == 6 and !(state >> 4 & 1)) return false;
return true;
}
int ones(int state) {
int res = 0;
while (state) state -= state & -state, res ++;
return res;
}
int res;
void dfs(int u, int state) {
if (ones(state) >= 4) res ++;
for (int i = 0; i < 9; i ++) {
if (!(state >> i & 1) and check(u, i, state)) dfs(i, state | (1 << i));
}
}
int main() {
for (int i = 0; i < 9; i ++) dfs(i, 1 << i);
printf("%d\n", res);
return 0;
}
666
666
哈哈哈哈真来啊
wow,谢谢滑稽gege