15 16 19 20 0
15 1896 16 5160 19 32757 20 59984
提交代碼:
#includeint ans[] = {0, 0, 0, 4, 6, 0, 0, 12, 40, 0, 0, 171, 410, 0, 0, 1896, 5160, 0, 0, 32757, 59984, 0, 0, 431095, 822229}; int main(){ int n; while(scanf("%d", &n), n) printf("%d %d\n", n, ans[n]); return 0; }
#includeint arr[26][26], ans[26], count; void DFS(int n){ if(n > 24) return; for(int i = 0; i <= 1; ++i){ arr[1][n] = i; count += arr[1][n]; for(int j = 2; j <= n; ++j){ arr[j][n-j+1] = arr[j-1][n-j+1] ^ arr[j-1][n-j+2]; count += arr[j][n-j+1]; } if(count * 2 == (1 + n) * n / 2) ++ans[n]; DFS(n + 1); //backTrack count -= arr[1][n]; for(int j = 2; j <= n; ++j){ arr[j][n-j+1] = arr[j-1][n-j+1] ^ arr[j-1][n-j+2]; count -= arr[j][n-j+1]; } } } int main(){ int n; DFS(1); for(int i = 1; i < 25; ++i) printf("%d, ", ans[i]); return 0; }