比赛 |
20120707 |
评测结果 |
AATTTTTTEE |
题目名称 |
奇怪的棋盘 |
最终得分 |
20 |
用户昵称 |
isabella |
运行时间 |
12.129 s |
代码语言 |
Pascal |
内存使用 |
0.41 MiB |
提交时间 |
2012-07-07 11:49:34 |
显示代码纯文本
const
inf=1000000007;
var
tot,n,i,j,k,ans:longint;
h,a,d:array[1..502]of longint;
v:array[1..502,1..502]of boolean;
f:array[1..502]of boolean;
function zhan(x:longint):boolean;
var i:longint;
begin
for i:=x to k do
if d[a[i]]=0 then exit(true);
exit(false);
end;
procedure make(x,now:longint);
var i,j,m,ii:longint;
begin
if x=k then begin ans:=(ans+now)mod inf;exit;end;
if zhan(x+1)then exit;
x:=x+1;
for i:=1 to h[a[x]] do
if v[a[x],i] then
begin
m:=n;
v[a[x],i]:=false;dec(d[a[x]]);
for j:=a[x]+1 to n do
begin
if h[j]<i then begin m:=j-1;break;end;
if f[j] then begin v[j,i]:=false;dec(d[j]);end;
//if d[j]<1 then exit;end;
end;
make(x,now);
for j:=m downto a[x] do
if f[j] then begin v[j,i]:=true;inc(d[j]);end;
end;
end;
procedure dfs(dn,x:longint);
var i:longint;
begin
if dn=k then
begin
a[k]:=x;f[x]:=true;
fillchar(v,sizeof(v),true);
d:=h;
make(0,1);exit;
end;
a[dn]:=x;f[x]:=true;
for i:=x+1 to n-k+dn+1 do dfs(dn+1,i);
f[x]:=false;
end;
begin
assign(input,'boarda.in');reset(input);
assign(output,'boarda.out');rewrite(output);
readln(n,k);
for i:=1to n do read(h[i]);
ans:=0;
for i:=1 to n+1-k do
begin
fillchar(f,sizeof(f),0);
dfs(1,i);
end;
writeln(ans);
close(input);close(output);
end.