#include #include #include #include #include #include #include #define MAXNB 1200 #define MOD 1000000007 int M[MAXNB]; long dp[MAXNB + 1][MAXNB + 1]; long fact[MAXNB + 1]; long combination[MAXNB + 1][MAXNB + 1]; void cal_factor() { long v = 1; fact[0] = 1; for (int i = 1; i <= MAXNB; ++i) { fact[i] = v = (v * i) % MOD; } } long cal_combi(int n, int m) { if (combination[n][m] >= 0) { return combination[n][m]; } if (n < m) { return 0; } if (m == 0) { combination[n][m] = 1; } else { combination[n][m] = (cal_combi(n - 1, m - 1) + cal_combi(n - 1, m)) % MOD; } return combination[n][m]; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &M[i]); } memset(dp, 0, sizeof(dp)); memset(combination, -1, sizeof(combination)); cal_factor(); dp[n][0] = 1; for (int i = n - 1; i >= 0; --i) { int mx = 0, last = -1; for (int j = i; j < n; ++j) { if (M[j] <= last) { break; } last = M[j]; ++mx; } for (int j = 1; j <= mx; ++j) { for (int k = 0; k <= j; ++k) { long c = cal_combi(j, k); long tmp = (((fact[k] * c) % MOD) * dp[i + j][k]) % MOD; dp[i][j] = (dp[i][j] + tmp) % MOD; } } } long ans = 0; for (int i = 1; i <= n; ++i) { ans = (ans + dp[0][i]) % MOD; } printf("%ld\n", ans); return 0; }