比赛 20110723 评测结果 AAAATTTTTT
题目名称 排列 最终得分 40
用户昵称 Yoghurt 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-23 11:11:26
显示代码纯文本
{
Problem:
Arithmetic Analysis:
Writer:
Data:
Remark:
AC:
}
program permutation;
const
        filename='permutation';
        maxn=100;
var
        n,m,ans,step:longint;
        vis:array[0..maxn] of boolean;
        path:array[0..maxn] of longint;

procedure check;
var
        i,tot:longint;
begin
        tot:=0;
        for i:=1 to n-1 do
                if path[i]<path[i+1] then
                        inc(tot);
        if tot=m then ans:=(ans+1) mod 2007;
end;

procedure dfs(x:longint);
var
        i:longint;
begin
        inc(step);
        vis[x]:=true;
        path[step]:=x;
        if step=n then check;
        for i:=1 to n do
                if not vis[i] then
                        dfs(i);
        dec(step);
        vis[x]:=false;
end;

procedure solve;
var
        i:longint;
begin
        while not eof do
        begin
                readln(n,m);
                ans:=0;
                for i:=1 to n do
                begin
                        step:=0;
                        dfs(i);
                end;
                writeln(ans);
        end;
end;

begin
        assign(input,filename+'.in'); reset(input);
        assign(output,filename+'.out'); rewrite(output);

        solve;

        close(input); close(output);
end.