Pagini recente » Cod sursa (job #2154574) | Cod sursa (job #2457472) | Cod sursa (job #931050) | Cod sursa (job #2833835) | Cod sursa (job #2047358)
#include <iostream>
#include <stdio.h>
using namespace std;
FILE *fin, *fout;
int st[14], vc[14];
int lin, col, l, j, n, x, k, contor=0;
int mod(int a, int b){
if(a>=b)
return a-b;
else
return b-a;
}
void bkt(int k){
int i, steag=0;
if(k==n+1){
if(contor==0)
for(l=1;l<=n;l++){
fprintf(fout,"%d ", st[l]);
}
contor++;
}
else{
for(i=1;i<=n;i++){
if(vc[i]==0){
vc[i]=1;
x=0;
steag=0;
j=1;
st[k]=i;
while(j<k){
if(mod(st[k], st[j])==mod(k, j))
steag=1;
j++;
}
if(steag==1)
st[k]=0;
else
bkt(k+1);
vc[i]=0;
}
}
}
}
int main() {
fin = fopen("damesah.in", "r");
fout = fopen("damesah.out", "w");
fscanf(fin,"%d", &n);
for(j=1;j<=n;j++)
vc[j]=0;
bkt(1);
fprintf(fout,"\n%d", contor);
fclose(fin);
fclose(fout);
return 0;
}