CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 20:02:16 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=0649b2320f3e222b9eaf43d764a03bf6042ccc09268260828a6cb88ff8a3079ba%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22NG5KQgVm2_274y5_wP-025jPupCP5dXi%22%3B%7D; HttpOnly; Path=/
cf-ray: 98d0f44518a425e0-BLR
#include <iostream>#include <vector>using namespace std;class Nqueens - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class Nqueens {
- int sol_count;
- int board_size;
- vector<int> solution_board;
- public:
- Nqueens(int size) : board_size(size), sol_count(0) {}
- bool is_valid(vector<int> board, int row_idx) {
- for (int i =0; i < board.size(); i++) {
- if (row_idx == board[i]) return false;
- }
- int curr_index = board.size();
- for (int i = 0; i < board.size(); i++) {
- if (board[i] + (curr_index-i) == row_idx || board[i] - (curr_index-i) == row_idx) return false;
- }
- return true;
- }
- void print_board(vector<int> board) {
- for (int i = 0; i < board.size(); i++) {
- for (int j = 0; j < board.size(); j++) {
- if (j == board[i]) {
- cout << "Q ";
- }
- else cout << "- ";
- }
- cout << endl;
- }
- }
- void search(vector<int> board, int curr_idx) {
- if (curr_idx == board_size) {
- print_board(board);
- sol_count++;
- cout << "Solution: " << sol_count << endl;
- }
- for (int i = 0; i < board_size; i++) {
- if (is_valid(board, i)) {
- board.push_back(i);
- search(board, curr_idx+1);
- board.pop_back();
- }
- }
- }
- void goal_search() {
- search(solution_board, 0);
- }
- void print_count() {
- cout << "Total solutions: " << sol_count << endl;
- }
- };
- int main() {
- Nqueens nq(15);
- nq.goal_search();
- nq.print_count();
- }
Advertisement
Add Comment
Please, Sign In to add comment
-
π Swapzone +37% glitch β O
JavaScript | 2 sec ago | 0.25 KB
-
π EASY MONEY GUIDE β
Working
JavaScript | 6 sec ago | 0.24 KB
-
ββ
Marketplace Glitch β
Working β
NEVER SEEN...
JavaScript | 7 sec ago | 0.25 KB
-
β
β Make huge profits on trading ββ 5
JavaScript | 11 sec ago | 0.25 KB
-
π ChangeNOW Exploit
JavaScript | 16 sec ago | 0.24 KB
-
ββ
Exploit 2500$ in 15 Minutesβββ P
JavaScript | 16 sec ago | 0.25 KB
-
ββ
Marketplace Glitch β
Working β
NEVER SEEN...
JavaScript | 19 sec ago | 0.25 KB
-
Free Crypto Method (NEVER SEEN BEFORE)ββ G
JavaScript | 25 sec ago | 0.25 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand