Cod sursa(job #1059757)

Utilizator Mihai_ChihaiMihai Chihai Mihai_Chihai Data 16 decembrie 2013 22:09:21
Problema Combinari Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.86 kb
program combinari;
var n,p,k,i:integer;
    st:array[1..1000] of integer;
    ev,as:boolean;
begin
assign(input,'combinari.in') ; reset(input);
assign(output,'combinari.out'); rewrite(output);
readln(n,p);
k:=1;  st[k]:=0;
while k>0  do begin
      repeat
         as:=false;
         if st[k]<n-p+k then begin inc(st[k]); as:=true; end;
         if as then begin
                  ev:=true;
                  for i:=1 to k-1 do if st[k]=st[i] then ev:=false;
                  if k>1 then if st[k]<st[k-1] then ev:=false;
                  end;
      until not as or (as and ev);
      if as then
         if k=p then begin for i:=1 to p do write(st[i],' '); writeln; end
                     else begin
                        k:=k+1;
                        st[k]:=0;
                        end
         else k:=k-1;
     end;
close(output);
end.