#include #define MOD 1000000007 #define MAXN 1234 using namespace std; typedef long long ll; int N; int A[MAXN]; ll fact[MAXN]; ll revfact[MAXN]; ll dp[MAXN][MAXN]; ll powr(ll base, int p) { if (p == 0) return 1LL; if (p == 1) return base; ll retval = powr(base, p/2); retval = (retval*retval)%MOD; if (p%2 == 1) retval = (retval*base)%MOD; return retval; } ll Solve(int idx, int last_size) { if (idx == N) return 1LL; if (dp[idx][last_size] != -1LL) return dp[idx][last_size]; ll retval = 0LL; for (int i=0; i 0 && A[idx+i-1] > A[i+idx]) break; /// cannot include them ll ways = (fact[last_size]*revfact[last_size-i-1])%MOD; ll mul = Solve(idx+i+1, i+1); retval = (retval + (ways*mul)%MOD)%MOD; } //cout << idx << " " << last_size << " : " << retval << endl; dp[idx][last_size] = retval; return retval; } int main() { fact[0] = 1LL; revfact[0] = 1LL; for (int i=1; i> N; for (int i=0; i> A[i]; memset(dp, -1LL, sizeof dp); ll answer = 0LL; for (int i=0; i 0 && A[i-1] > A[i]) break; answer = (answer + Solve(i+1, i+1))%MOD; } cout << answer << endl; return 0; }