fork download
  1. {$mode objfpc}
  2. uses math;
  3. const
  4. finp = '';
  5. fout = '';
  6. modulo = trunc(1e9+7);
  7. maxn = 2000;
  8. var
  9. fi,fo : text;
  10. n,h : integer;
  11. f : array[1..maxn,0..maxn] of int64;
  12. a : array[1..maxn] of integer;
  13. procedure openfile;
  14. begin
  15. assign(fi,finp);reset(fi);
  16. assign(fo,fout);rewrite(fo);
  17. end;
  18. procedure closefile;
  19. begin
  20. close(fi);close(fo);
  21. end;
  22. procedure enter;
  23. var
  24. i : integer;
  25. begin
  26. readln(fi,n,h);
  27. for i:=1 to n do
  28. read(fi,a[i]);
  29. end;
  30. procedure add(var a:int64;b:int64);
  31. begin
  32. a:=(a+b) mod modulo;
  33. end;
  34. procedure process;
  35. var
  36. i,j : integer;
  37. begin
  38. //Tai 1 [] hoac do no thing
  39. f[1][0]:=ord((a[i]=h) or (a[i]+1=h));
  40. //Tai 1 [
  41. f[1][1]:=ord(a[i]+1=h);
  42. for i:=2 to n do
  43. for j:=max(h-a[i]-1,0) to min(h-a[i],i) do
  44. begin
  45. //
  46. if j+a[i]=h then
  47. begin
  48. //Tai i [
  49. if j>0 then
  50. add(f[i,j],f[i-1,j-1]);
  51. //Do no thing
  52. add(f[i,j],f[i-1,j]);
  53. end
  54. else
  55. if j+a[i]+1=h then
  56. begin
  57. //Tai i ]
  58. add(f[i,j],f[i-1,j+1]*(j+1));
  59. //Tai i []
  60. add(f[i,j],f[i-1,j]);
  61. //Tai i ][
  62. add(f[i,j],f[i-1,j]*j);
  63. end;
  64. end;
  65. writeln(fo,f[n,0]);
  66. end;
  67. begin
  68. openfile;
  69. enter;
  70. process;
  71. closefile;
  72. end.
Success #stdin #stdout 0s 31680KB
stdin
3 2
1 1 1
stdout
4