Cod sursa(job #362438)

Utilizator bodyionitaIonita Bogdan Constantin bodyionita Data 9 noiembrie 2009 18:59:35
Problema Combinari Scor 80
Compilator fpc Status done
Runda Arhiva educationala Marime 0.92 kb
var f,g:text;
    st:array[1..100] of byte;
   p,K,i,n:integer;
    ev,as:boolean;
procedure succesor;
begin
    if st[k]<n then
     begin
      as:=true;
      st[k]:=st[k]+1;
     end
     else
     as:=false;
 end;
procedure valid;
 begin
  ev:=true;
  for i:=1 to k-1 do
   if (st[i]>=st[i+1])  then
   ev:=false;
 end;
procedure init;
begin
st[k]:=0;
end;
 
function solutie:boolean;
begin
solutie:=(p=k);
end;
 
procedure tipar;
begin
 for i:=1 to p do
 write(g,st[i],' ');
 writeln(g);
end;
 
BEGIN
assign(f,'combinari.in');reset(f);
read(f,n,p);close(f);
assign(g,'combinari.out');rewrite(g);
k:=1;init;
while k>0 do
 begin
   repeat
    succesor;
    if as then valid
  until (as and ev) or (not as);
  if (as) and (ev) then
     if solutie  then
       tipar
       else
        begin
         k:=k+1;
        init
        end
    else
   k:=k-1;
 end;
close(g);
END.