Lab 10 Daa
Lab 10 Daa
For
CODE-
#include <iostream>
#include <vector>
#include <limits>
// If this state has already been computed, return the stored result
if (dp[mask][pos] != -1) {
return dp[mask][pos];
}
int main() {
// Define the number of cities
int n;
cout << "Enter the number of cities: ";
cin >> n;
return 0;
}
OUTPUT-
Q2) N Queens
CODE-
#include <iostream>
#include <vector>
#include <algorithm> // Include the <algorithm> header for std::find
class NQueens {
public:
NQueens(int n) : n(n), board(n, vector<char>(n, '.')) {}
// Function to solve the N-Queens problem
void solve() {
backtrack(0);
}
private:
int n;
vector<vector<char>> board;
vector<int> cols; // Keep track of columns used
vector<int> diag1; // Keep track of major diagonals used
vector<int> diag2; // Keep track of minor diagonals used
return true;
}
};
int main() {
int n;
cout << "Enter the value of N (number of queens): ";
cin >> n;
NQueens solver(n);
cout << "Solutions:" << endl;
solver.solve();
return 0;
}
OUTPUT-