提交时间:2023-10-28 09:30:51
运行 ID: 107756
#include<iostream> using namespace std; int res[20], n, cnt = 0; bool vis[25], line1[50], line2[50]; void f(int pos){ if (pos >= n){ if (cnt < 3){ for(int i = 0; i < n; i++){ cout << res[i] << ' '; } cout << endl; } cnt++; return; } for(int i = 1; i <= n; i++){ int x = pos, y = i; if(!vis[i] && !line1[x - y + n] && !line2[x + y]){ res[pos] = i; vis[i] = line1[x - y + n] = line2[x + y] = true; f(pos + 1); vis[i] = line1[x - y + n] = line2[x + y] = false; } } } int main(){ cin >> n; f(0); cout << cnt; return 0; }