#include #include #include #include #include #include using namespace std; namespace { const int N = 1300; const int MOD = (int) 1e9 + 7; int dp[N][N]; int c[N][N], p[N][N], fact[N]; } inline void Mod(int& a) { if (a >= MOD) a -= MOD; } void init() { c[0][0] = 1; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < N - 1; j++) { Mod(c[i+1][j] += c[i][j]); Mod(c[i+1][j+1] += c[i][j]); } } fact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = (fact[i-1] * 1LL * i) % MOD; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { p[i][j] = (c[i][j] * 1LL * fact[j]) % MOD; } } } int main() { init(); int n; cin >> n; vector a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { if (i > 1 && a[i] < a[i - 1]) break; dp[i][i] = 1; } for (int i = 1; i < n; i++) { for (int x = 1; x <= n - i; x++) { if (x > 1 && a[i + x] < a[i + x - 1]) break; int sum = 0; for (int k = x; k <= n; k++) { sum += (dp[i][k] * 1LL * p[k][x]) % MOD; if (sum >= MOD) sum -= MOD; } Mod(dp[i + x][x] += sum); } } int ans = 0; for (int i = 1; i <= n; i++) { Mod(ans += dp[n][i]); } cout << ans << "\n"; #ifdef HOUSE cerr << "Time: " << setprecision(3) << (double) clock() / CLOCKS_PER_SEC << " sec.\n"; #endif return 0; }