Pagini recente » Cod sursa (job #2844942) | Cod sursa (job #562803) | Cod sursa (job #61224) | Cod sursa (job #2771268) | Cod sursa (job #1086238)
#include <cstdio>
int regine[14];
int col[14];
int principal[27];
int secundar[27];
int np;
void bkt( FILE *fout, int l, int n ) {
int c;
if ( l == n ) {
if ( ++np < 2 ) {
for ( c = 0; c < n; c++ )
fprintf( fout, "%d ", regine[c] + 1 );
fprintf( fout, "\n" );
}
} else {
for ( c = 0; c < n; c++ ) {
if ( !col[c] && !principal[c-l+n-1] && !secundar[l+c] ) {
regine[l] = c;
col[c] = principal[c-l+n-1] = secundar[l+c] = 1;
bkt( fout, l + 1, n );
col[c] = principal[c-l+n-1] = secundar[l+c] = 0;
}
}
}
}
int main () {
FILE *fin, *fout;
fin = fopen( "damesah.in", "r" );
int n;
fscanf( fin, "%d", &n );
fclose( fin );
fout = fopen( "damesah.out", "w" );
np = 0;
bkt( fout, 0, n );
fprintf( fout, "%d\n", np );
fclose( fout );
}