#include #include using namespace std; #define N 1205 #define M 1000000007 #define ll long long ll dp[N][N],pos[N],sum[N][N],a[N],fact[N],pre[N][N]; long long power(long long a,long long b) { long long x=(a)%M,y=1; while(b) { if(b%2!=0) y=(y*x)%M; x=(x*x)%M; b/=2; } return y; } ll f(ll n,ll r) { if(n>n; for(i=1;i<=n;i++) cin>>a[i]; fact[0]=1; for(i=1;ia[j-1]) { pos[i]=j; } else break; } //cout<=1;i--) { for(j=1;j<=n;j++) { if(i+j-1>pos[i]) break; if(i+j-1==n && pos[i]==n) dp[i][j]=1; else { for(int k=j;k>=1;k--) dp[i][j]=(dp[i][j]+ (((pre[j][k]*fact[k])%M)*(dp[i+j][k]))%M )%M; } } for(j=1;j<=n;j++) sum[i][j]=(sum[i][j-1]+dp[i][j])%M; } cout<