Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
107789 | 宋春霖 | 跳棋的挑战 | C++ | 通过 | 100 | 307 MS | 248 KB | 601 | 2023-10-28 09:57:05 |
#include<bits/stdc++.h> using namespace std; int a[105], n, cnt; bool b[105], c[105], d[105]; void dfs(int i){ if (i > n){ cnt ++; if (cnt <= 3){ for (int k = 1; k <= n; k++){ cout << a[k]; if (k < n) cout << " "; } cout << endl; } } else { for (int k = 1; k <= n; k++){ if (!b[k] && !c[i + k] && !d[i - k + n]){ b[k] = true; c[i + k] = true; d[i - k + n] = true; a[i] = k; dfs(i + 1); b[k] = false; c[i + k] = false; d[i - k + n] = false; } } } } int main(){ cin >> n; dfs(1); cout << cnt; }