#include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX = 1300; const ll mod = 1000000007LL; ll factorial[MAX]; void calcFactorial(int n){ factorial[0] = 1; for(int i = 1;i<=n;++i){ factorial[i] = (i*factorial[i-1]) % mod; } } ll pow(ll a, ll p){ if(p == 0){ return 1; } ll res = pow(a, p/2); res *= res; res %= mod; if(p % 2 == 1){ res *= a; res %= mod; } return res; } ll dp[1201][1201]; ll choose[1201][1201]; void generateChoose(int n){ choose[0][0] = 1; for(int i = 1;i<=n;++i){ for(int j = 0;j<=i;++j){ choose[i][j] = 0; if(j > 0){ choose[i][j] += choose[i-1][j-1]; choose[i][j] %= mod; } if(j <= i-1){ choose[i][j] += choose[i-1][j]; choose[i][j] %= mod; } } } } inline ll getRes(int maxRow, int pos, bool *br, int n){ if(pos == n){ return 1; } if(maxRow == 1){ return 1; } if(dp[maxRow][pos] != -1){ return dp[maxRow][pos]; } ll res = 0; /// apply curr row for(int row = 1;row <= maxRow && pos+row <= n && (row == 1 || !br[pos+row-1]);++row){ res += (((choose[maxRow][row]*factorial[row]) % mod)*getRes(row, pos+row, br, n)) % mod; res %= mod; } return dp[maxRow][pos] = res; } int main(){ ios::sync_with_stdio(false); int n; cin>>n; calcFactorial(n+1); generateChoose(n); int m[n]; for(int i = 0;i>m[i]; } bool br[n+1]; for(int i = 0;i