# jzoj. 3505. 【NOIP2013模拟11.4A组】积木(brick)

Description

Input

Output

Sample Input

3

-1 2 -1

-1 -1 -1

6

-1 -1 -1 2 -1 -1

Sample Output

0

2

3

Data Constraint

（水解）：

f[i,j]=sum(f[i-1,j-1],f[i-1,j],f[i-1,j+1])

（正解）：对于每两个有确定高度的点，即a[i]≠-1(或者是两端的0)，考虑中间的方案数。

{a[i],a[i+1],a[i+2],……a[j]}

{a[i+1]-a[i],a[i+2]-a[i],……a[j]-a[j-1]}

{中间有m个空位，1有sum+x个；对于剩余的m-sum-x个位置，-1有x个；剩余的位置都是0，方案显然是1，相乘结果不变}

(n!)^(-1)=(n!)^(p-2)

const
modd=1000000007;
var
f:array [0..1,-1..20001] of int64;
a,max:array [0..20001] of longint;
n,i,j,x,s,t,m,y:longint;
begin
assign(input,'brick.in');
assign(output,'brick.out');
reset(input);
rewrite(output);
for i:=1 to n do
if a[1]>0 then
begin
writeln(0);
close(input);
close(output);
exit;
end;
m:=n div 2+1;
for i:=1 to n do
if i<m then max[i]:=i-1 else max[i]:=n-i;
x:=0;
f[x,0]:=1;
for i:=2 to n do
begin
y:=x;
x:=1-x;
fillchar(f[x],sizeof(f[x]),0);
if a[i]=-1 then
begin
if i mod 10=0 then
for j:=0 to max[i] do
f[x,j]:=(f[y,j-1]+f[y,j]+f[y,j+1])mod modd
else
for j:=0 to max[i] do
f[x,j]:=f[y,j-1]+f[y,j]+f[y,j+1];
end
else
f[x,a[i]]:=(f[y,a[i]-1]+f[y,a[i]]+f[y,a[i]+1])mod modd;
end;
writeln(f[x,0] mod modd);
close(input);
close(output);
end.


const mo=1000000007;
var
n,i,j,k,l,h:longint;
a:array[1..20000]of longint;
jc,ny:array[0..20000]of longint;
ans,tot:longint;
function ksm(x,y:longint):longint;
begin
if y=1 then exit(x);
ksm:=ksm(x,y>>1);ksm:=int64(ksm)*ksm mod mo;
if y and 1=1 then ksm:=int64(ksm)*x mod mo;
end;
function c(a,b:longint):longint;
begin
if a>b then exit(0);
exit(int64(jc[b])*ny[a]mod mo*ny[b-a]mod mo);
end;
begin
assign(input,'brick.in');reset(input);
assign(output,'brick.out');rewrite(output);
jc[0]:=1;for i:=1 to n do jc[i]:=int64(jc[i-1])*i mod mo;
ny[n]:=ksm(jc[n],mo-2);for i:=n-1 downto 0 do ny[i]:=int64(ny[i+1])*(i+1)mod mo;
if(a[1]>0)or(a[n]>0)then
begin
writeln(0);halt;
end;
a[1]:=0;a[n]:=0;i:=1;j:=1;ans:=1;
while i<n do
begin
inc(i);if a[i]>-1 then
begin
tot:=0;h:=abs(a[i]-a[j]);
for k:=0 to i-j-h do
begin
l:=i-j-k;if (l+h)and 1=1 then continue;
tot:=(tot+int64(c(k,i-j))*(c((l+h)>>1,l)-c((l+a[i]+a[j]+2)>>1,l))mod mo+mo)mod mo;
end;
ans:=int64(tot)*ans mod mo;j:=i;
end;
end;
writeln(ans);
end.

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120