比赛 20120707 评测结果 AAAATEEEEE
题目名称 奇怪的棋盘 最终得分 40
用户昵称 SnowDancer 运行时间 2.414 s
代码语言 Pascal 内存使用 32.17 MiB
提交时间 2012-07-07 11:29:20
显示代码纯文本
program boarda;
const
  base=1000000007;
var
  n,i,j,k,l,tot:longint;
  f:array[0..15,0..15,0..32767] of longint;
  h,fac:array[0..15] of longint;
  ans:longint;
function min(x,y:longint):longint;
  begin  if x<y then exit(x) else exit(y); end;
begin
assign(input,'boarda.in');reset(input);
assign(output,'boarda.out'); rewrite(output);
  readln(n,tot);
  for i:=1 to n do read(h[i]);
  for i:=1 to n do fac[i]:=fac[i-1]*2+1;
  f[0,0,0]:=1;
  for i:=1 to n do
    for j:=0 to min(tot,i-1) do
      for k:=0 to fac[h[i-1]] do begin
        f[i,j,k and fac[h[i]]]:=(f[i-1,j,k]+f[i,j,k and fac[h[i]]]) mod base;
        if j<tot then
          for l:=1 to h[i] do
            if (l>h[i-1]) or (k shr (l-1) and 1=0) then begin
              f[i,j+1,(k xor (1<<(l-1))) and fac[h[i]]]:=
                (f[i-1,j,k]+f[i,j+1,(k xor (1<<(l-1))) and fac[h[i]]]) mod base;
            end;
      end;
  for i:=0 to fac[h[i]] do
    ans:=(f[n,tot,i]+ans) mod base;
  writeln((ans+base) mod base);
close(input);close(output);
end.