Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <stdlib.h>
- using namespace std;
- int brResenja=0;
- int n;
- int e=0; //poziv kraljice(0)
- int i=1; //poziv dozvola(0)
- static vector<int> kolone; //cuvaju indeks pozicije kraljice
- void kraljice(int e); //pretraga resenja
- bool dozvola(int i); //provera dozvole
- int main(int argc, char *argv[]) {
- cout<<"Unesi dimenzije tabele(n): "<<endl;
- cin>>n;
- if(n>0)
- {
- for(int a=0; a<n; a++) {
- kolone.push_back(0);
- }
- kraljice(e);
- cout<<"Broj resenja: "<<brResenja<<endl;
- }
- return 0;
- }
- void kraljice(int i) {
- if(dozvola(i-1)) {
- if(i==n) brResenja++;
- else {
- for(int l=0; l<n; l++){
- kolone[i]= l;
- kraljice(i+1);
- }
- }
- }
- }
- bool dozvola(int i) {
- for(int s=0; s<i; s++)
- if(kolone[i]==kolone[s] || abs(kolone[i] -kolone[s])== i-s) return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement