Description
Input
Output
Sample Input
4
1701 1702 1703 1704
Sample Output
8
HINT
水题,区间dp,f[l,r,k]表示区间[l,r]最后一个是左(k=0)还是右(k=1)的方案数
1 const 2 maxn=1010; 3 h=19650827; 4 var 5 f:array[0..maxn,0..maxn,0..1]of longint; 6 a:array[0..maxn]of longint; 7 n:longint; 8 9 procedure init; 10 var 11 i:longint; 12 begin 13 read(n); 14 for i:=1 to n do 15 begin 16 read(a[i]); 17 f[i,i,0]:=1; 18 end; 19 end; 20 21 procedure dp; 22 var 23 i,j:longint; 24 begin 25 for i:=1 to n-1 do 26 for j:=1 to n-i do 27 begin 28 f[j,j+i,0]:=(longint(a[j]<a[j+1])*f[j+1,j+i,0]+longint(a[j]<a[j+i])*f[j+1,j+i,1])mod h; 29 f[j,j+i,1]:=(longint(a[j+i]>a[j])*f[j,j+i-1,0]+longint(a[j+i]>a[j+i-1])*f[j,j+i-1,1])mod h; 30 end; 31 writeln((f[1,n,0]+f[1,n,1])mod h); 32 end; 33 34 begin 35 init; 36 dp; 37 end.