First, the sequence is called a magic Purfer sequence, he can represent a tree, and each node occurs in this case the degree of -1 ( thus a total length of 2-n- ) .
Then DP , with F [i] [j] [k] is represented by the front i th points j points constitute a length k of Purfer sequence (of course, to meet the criteria), then it is $ F [i] [j ] [k] = f [i -1] [j] [k] + \ sum \ limits_ {i = 0} ^ {a [i] -1} f [i-1] [j-1] [kl] \ CDOT C (k, L) $ , may similarly eliminate backpack I ( J and k to reverse), and then can be recursive.
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define N 105 4 #define mod 1000000007 5 int t,n,a[N],f[N][N],c[N][N]; 6 int main(){ 7 for(int i=0;i<=100;i++)c[i][0]=c[i][i]=1; 8 for(int i=2;i<=100;i++) 9 for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; 10 scanf("%d",&t); 11 while (t--){ 12 scanf("%d",&n); 13 memset(f,0,sizeof(f)); 14 f[0][0]=1; 15 for(int i=1;i<=n;i++)scanf("%d",&a[i]); 16 for(int i=1;i<=n;i++) 17 for(int j=i;j;j--) 18 for(int k=n-2;k>=0;k--) 19 for(int l=0;l<a[i];l++) 20 f[j][k]=(f[j][k]+1LL*f[j-1][k-l]*c[k][l])%mod; 21 printf("%d ",n); 22 for(int i=2;i<n;i++)printf("%d ",f[i][i-2]); 23 printf("%d\n",f[n][n-2]); 24 } 25 }