比赛 |
2008haoi模拟训练1 |
评测结果 |
AAAAAAAAAA |
题目名称 |
分组 |
最终得分 |
100 |
用户昵称 |
梦里醉逍遥 |
运行时间 |
0.004 s |
代码语言 |
Pascal |
内存使用 |
0.22 MiB |
提交时间 |
2008-04-22 08:41:46 |
显示代码纯文本
program dataa;
const
fi='dataa.in'; fo='dataa.out';
type
arr=array[1..6] of longint;
que=array[1..1000] of arr;
var
fin,fout:text;
m,n,num:longint;
c:arr; ans:que;
procedure init;
begin
assign(fin,fi); reset(fin);
readln(fin,n,m); close(fin);
end;
procedure print;
var
i,j:longint;
begin
assign(fout,fo); rewrite(fout);
writeln(fout,num);
for i:=1 to num do begin
for j:=1 to m-1 do write(fout,ans[i,j],' ');
writeln(fout,ans[i,m]);
end;
close(fout);
end;
function pd(c:arr):boolean;
var
i:longint;
begin
pd:=false;
for i:=1 to m-1 do
if c[i]>c[i+1] then exit;
pd:=true;
end;
procedure make(x:longint;c:arr);
var
i,j:longint;
begin
for i:=1 to c[m]-1 do begin
c[x]:=c[x]+1;
c[m]:=c[m]-1;
if pd(c) then begin
num:=num+1;
for j:=1 to m do ans[num,j]:=c[j];
end;
for j:=m-1 downto x+1 do make(j,c);
end;
end;
procedure main;
var
i,j:longint;
begin
if m>n then begin
num:=0;
print; halt;
end;
if m=n then begin
num:=1;
for i:=1 to m do ans[1,i]:=1;
print;
halt;
end;
for i:=1 to m-1 do c[i]:=1;
c[m]:=n-m+1; num:=1;
for i:=1 to m do ans[num,i]:=c[i];
for i:=m-1 downto 1 do make(i,c);
end;
begin
init;
main;
print;
end.