一道不错的想法题。。。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int LL;
const LL maxn=2200,MOD=1e9+7;
LL a[maxn],b[maxn];
int main()
{
int n,h;
cin>>n>>h;
for(int i=1;i<=n;i++)
{
cin>>a[i];
a[i]=h-a[i];
}
for(int i=1;i<=n+1;i++)
{
b[i]=a[i]-a[i-1];
}
LL ans=1,cnt=0;
for(int i=1;i<=n+1;i++)
{
if(b[i]==1)
{
cnt++;
}
else if(b[i]==0)
{
if(cnt) ans=(ans*(cnt+1))%MOD;
}
else if(b[i]==-1)
{
ans=(ans*cnt)%MOD;
cnt--;
}
else ans=0;
}
cout<<ans<<endl;
return 0;
}