题目连接:
Description
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a CS, did a research on data structure.
Now Clarke has n nodes, he knows the degree of each node no more than ai. He wants to know the number of ways to choose some nodes to compose to a tree of size s(1≤s≤n).Input
The first line contains one integer T(1≤T≤10), the number of test cases.
For each test case: The first line contains an integer n(2≤n≤50). Then a new line follow with n numbers. The ith number ai(1≤ai<n) denotes the number that the degree of the ith node must no more than ai.Output
For each test case, print a line with n integers. The ith number denotes the number of trees of size i modulo 109+7.
Sample Input
1
3 2 2 1Sample Output
3 3 2
Hint:
At first we know the degree of node 1 can not more than 2, node 2 can not more than 2, node 3 can not more than 1. So
For the trees of size 1, we have tree ways to compose, are 1, 2 and 3. i.e. a tree with one node. For the trees of size 2, we have tree ways to compose, are 1-2, 1-3, 2-3. For the trees of size 3, we have two ways to compose, are 1-2-3, 2-1-3.题意
给你n个点,每个点的度数最多为a[i]
然后分别问你点数为s的树,一共有多少种,(1<=s<=n)题解:
考虑prufer的序列
对于点数为s,在这道题中z可以转化为这样:长度为s-2的序列里面,s个数都出现小于a[i]次的序列个数有多少个 我们直接n^4dp就好了 dp[i][j][k]表示考虑到了第i个数,我用了j,当前序列的长度为k的方案数代码
#includeusing namespace std;const int mod = 1e9+7;const int maxn = 62;long long dp[maxn][maxn][maxn];//考虑到了第i个点,现在出现了j个数,长度为k的方案数long long c[maxn][maxn];int a[maxn],n;void init(){ for(int i=0;i