Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- #include <math.h>
- int st[100],k, n,i,j;
- void init()
- {
- st[k]=0;
- }
- int succesor()
- {
- if(st[k]<n)
- {
- st[k]++;
- return 1;
- }
- else
- return 0;
- }
- int valid()
- {
- for(i=1;i<k;i++)
- if(st[k]==st[i]||abs(st[k]-st[i])==abs(k-i)) return 0;
- return 1;
- }
- int solutie()
- {
- return k==n;
- }
- void tipar()
- { cout<<endl;
- for(i=1;i<=k;i++)
- {cout<<endl; for(j=1;j<=k;j++)
- if(st[i]==j) cout<<"D";
- else cout<<"*";
- cout<<endl;}
- }
- void btr()
- {
- int AS;
- k=1;
- init();
- while(k>0)
- {
- do
- {}while((AS=succesor())&& (!valid()));
- if(AS)
- if(solutie())
- tipar();
- else
- {
- k++;
- init();
- }
- else k--;
- }
- }
- int main()
- {
- cin>>n;
- btr();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement