#include #define MOD 1000000007 #define LL long long #define Nmax 1201 using namespace std; int n,v[Nmax]; LL P[Nmax],DP[Nmax][Nmax],inv[Nmax],rez; LL aranj(LL n, LL m) { return (P[n] * inv[n-m])%MOD; } LL invMOD(LL a,LL b) { if (b==1) return a; if (b%2==0) return invMOD((a*a)%MOD,b/2); return (invMOD((a*a)%MOD,b/2)*a)%MOD; } int main() { cin>>n; for (int i=1;i<=n;i++) { cin>>v[i]; } P[1] = 1; inv[1] = 1; inv[0] = 1; for (int i=2;i<=n;i++) { P[i] = (P[i-1]*i)%MOD; inv[i] = invMOD(P[i],MOD-2); } int lst = 1; for (int i=0;i<=n;i++) DP[0][i] = 1; for (int i=1;i<=n;i++) { if(v[i]=1;j--) { if (j==i) DP[i][j]=1; else for (int k=j;k<=i;k++) DP[i][j] = (DP[i][j] + (DP[i-j][k]*aranj(k,j))%MOD)%MOD; if (i==n) rez=(rez+DP[i][j])%MOD; } } cout<