# Ask Question

 Name: Title:
 Your Question:

# Answer Question

 Name:
 Your Answer:
ONLINE COMPILERS
LIBRARY
MANUAL PAGES & DOCS
CONTACT

User Submitted Source Code!

Description:
problema damelor
Language: PASCAL
Code:
program regina;
uses crt;
var     st:array[1..25] of integer;
n:integer;
f:text;

procedure init;
var i:integer;
begin
write('nr de regine? :");
readln(n);
for i:=1 to 50 do st[i]:=0;
end;

procedure scrie;
var i,j:integer;
begin
for i:= 1 to n do
begin
for i:= 1 to n do
if st[i]:=j then write(f,"r")
else write(f,”x”);
writeln(f);
end;
writeln(f);
end;

function adev(p:integer):boolean;
var     i:integer;
pos:boolean;
begin
pos:=true;
for i:= 1 to p-1 do
if (st[p]=st[i]) or (abs(st[p]-st[i])=abs(p-1)) then pos:=false;
valid:=pos;
end;

procedure bktrack(p:integer);
var     val:integer;
begin
for val:= 1 to n do
begin
st[p]:= val;
if valid(p) then if p=n then scrie
else bktrack(p+1);
end;
end;

begin
clrscr;
assign(f,’C:programregina.txt’);
rewrite(f);
initializari;
bktr(1);
close(f);
writeln(‚sunt sol in fis regina.txt’);
readln;
end.

Comments: