Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl '\n'
- typedef long long ll;
- using namespace std;
- const int N = 8;
- int total = 0;
- void print(vector<int> &v) {
- cout << "{\n";
- for (int i = 0; i < N; ++i) {
- cout << " {";
- for (int j = 0; j < N; ++j) {
- cout << (v[i] == j) << ", ";
- }
- cout << "},\n";
- }
- cout << "},\n";
- }
- void f(vector<int> v, int row) {
- if (row == N) {
- total++;
- print(v);
- return;
- }
- for (int col = 0; col < N; ++col) {
- bool ok = 1;
- for (int i = 0; i < row; ++i) {
- int j = v[i];
- if (j == col || row+col == i+j || row-col == i-j) {
- ok = 0;
- break;
- }
- }
- if (ok) {
- v[row] = col;
- f(v, row+1);
- }
- }
- }
- void start() {
- vector<int> v(N, -1);
- for (int j = 0; j < N; ++j) {
- v[0] = j;
- f(v, 1);
- }
- }
- void main1() {
- start();
- cout << "Total amount: " << total << endl;
- }
- int main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- std::cout.tie(nullptr);
- #ifdef _DEBUG
- std::freopen("in.txt", "r", stdin);
- std::freopen("out.txt", "w", stdout);
- #endif
- main1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement