#include using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef long long ll; const int mod = (int) 1e9 + 7; const int MAX = 1205; int n; int arr[MAX]; ll dp[MAX][MAX]; ll cp[MAX][MAX]; ll fact[MAX]; void calc() { cp[0][0] = 1; for(int i=1;i=n) return 1; ll& r = dp[i][l]; if(r!=-1) return r; r = (1LL * (i==0 ? 1 : cp[l][1]) * solve(i+1,1))%mod; for(int j=i+1;j arr[j-1] && j-i+1 <= l) r = (r + ((i==0 ? 1 : (cp[l][j-i+1]*fact[j-i+1])%mod) * solve(j+1,j-i+1)))%mod; else break; } return r; } int main() { calc(); // for(int i=0;i<5;i++){ // for(int j=0;j<=i;j++) // cout << cp[i][j] << " "; // cout << endl; // } scanf("%d",&n); for(int i=0;i