Pagini recente » Cod sursa (job #1422912) | Cod sursa (job #1526485) | Cod sursa (job #300932) | Cod sursa (job #2285356) | Cod sursa (job #1059757)
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.