#include #include #include using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair ii; typedef vector vi; typedef long double ld; typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set::iterator sit; typedef map::iterator mit; typedef vector::iterator vit; int a[1201]; const int MOD = 1e9 + 7; ll dp[1201][1201]; ll nxt[1201]; ll ifact[1201]; ll fact[1201]; ll modpow(ll x,ll b) { ll r=1; while(b) { if(b&1) r=(r*x)%MOD; x=(x*x)%MOD; b>>=1; } return r; } ll inv(ll x) { return modpow(x,MOD-2); } ll d[1201][1201]; ll c(ll n, ll r) { if(r==0) return 1; if(n>n; memset(d,-1,sizeof(d)); for(int i = 0; i < n; i++) { cin>>a[i];a[i]--; } fact[0]=1; for(int i=1;i<=1200;i++) fact[i]=(fact[i-1]*i)%MOD; ifact[0]=1; for(int i=1;i<=1200;i++) ifact[i]=inv(fact[i]); nxt[n-1]=n-1; for(int i = n - 2; i >= 0; i--) { if(a[i]= 0; i--) { for(int j = 1; j <= n; j++) { if(j<=nxt[i]-i+1) { for(int k = 0; k <= j; k++) { dp[i][j] = (dp[i][j] + ((dp[i+j][k]*fact[j])%MOD*c(j,k))%MOD)%MOD; } } //cerr<0) dp[i][j] = (dp[i][j]+dp[i][j-1])%MOD; } } ll ans = 0; for(int i = 1; i <= n; i++) { ans=(ans+(dp[0][i]*ifact[i])%MOD)%MOD; } cout<