#include #include #include #include using namespace std; const int MAXN = 1210; const int mod = 1e9+7; typedef long long int lint; int n,ar[MAXN]; lint dp[MAXN][MAXN]; lint comb[MAXN][MAXN]; lint fact[MAXN]; lint calc_comb(int n,int r){ if(r<0 || r>n) return 0; if (n==r || r==0) return 1; lint &rev = comb[n][r]; if (rev!=-1LL) return rev; return rev = (calc_comb(n-1,r-1) + calc_comb(n-1,r))%mod; } lint calc_perm(int n,int r){ return (calc_comb(n,r)*fact[r])%mod; } lint solve(int index, int cont){ // printf("solve index:%d cont:%d\n",index,cont); lint &rev = dp[index][cont]; if (rev!=-1) return rev; if (index==n) return rev = 1; rev = 0; int last = -1; for (int i=index+1; i<=n && i-index<=cont; i++){ if (ar[i] to %d,%d\n",index, cont, i, i-index); lint times = 1LL; if (index != 0) times = calc_perm(cont,i-index); rev = (rev + (solve(i,i-index)*times)%mod)%mod; } return rev; } int main(){ scanf(" %d",&n); for(int i=1; i<=n; i++){ scanf(" %d",ar+i); } fact[0]=1LL; for (int i=1;i<=n;i++) fact[i]=(fact[i-1]*i)%mod; for(int i=0; i<=n; i++) for(int j=0;j<=n;j++) comb[i][j]=dp[i][j]=-1LL; cout << solve(0,n) << endl; return 0; }