Uva_10247
Let's first discuss this situation when the K-tree is changed from n-1 to n-layer to see if a recursive formula can be obtained.
If f [I] is set to represent the number of solutions for K-tree N layers, and g [I] is set to the number of vertices when K-tree I layers are set to N layers, the minimum number of root nodes is required. What about the child nodes of the root node? Because tags are different, you can select G [n-1] tags from the remaining tags for each subtree. In this way, we obtain the recursive formula F [N] = multiply {C (I * g [n-1], G [n-1]). * f [n-1]} (1 <= I <= K ).
So we can pre-process all the results first.
Import Java. Math. biginteger;
Import Java. util. vendor;
Public Class Main {
Public Static Void Main (string [] ARGs ){
Scanner CIN = New Using (system. In );
Biginteger [] [] f = New Biginteger [30] [30];
Int [] [] G = New Int [30] [30];
For ( Int I = 1; I <= 21; I ++)
{
F [I] [0] = New Biginteger ("1 ");
G [I] [0] = 1;
For ( Int J = 1; I * j <= 21; j ++)
{
F [I] [J] = New Biginteger ("1 ");
G [I] [J] = I * g [I] [J-1];
G [I] [J] ++;
For ( Int K = I; k> = 1; k --)
F [I] [J] = f [I] [J]. multiply (F [I] [J-1]. multiply (C (K * g [I] [J-1], G [I] [J-1]);
}
}
While (CIN. hasnext ())
{
Int K = cin. nextint ();
Int D = cin. nextint ();
System. Out. println (F [k] [d]);
}
}
Public Static Biginteger C ( Int M,Int N)
{
If (M-n <n)
N = m-N;
Biginteger res = New Biginteger ("1 ");
For ( Int I = 1; I <= N; I ++)
Res = res. Multiply (biginteger. valueof (M-I + 1). Divide (biginteger. valueof (I ));
Return Res;
}
}