1#include <stdio.h>2 intssintNintk)3 {4 if(n==k| | k==1)return 1;5 returnSS (n1, K-1) +K*SS (n1, K); 6 }7 intMain ()8 {9 ints,n,k;Tenscanf"%d%d",&n,&k); OneN>=k?s=ss (n,k): s=-1; Aprintf"%d", s); - return 0; -}
The division of a set is the composition of the number of sets of a set, where n is the number of elements and K is the number of sets
The specific rules are
1, Sn∉∅;
2, Si∩sj∈∅ (1≤i,j≤k i≠j);
3. S1∪s2∪s3∪ ... ∪sk=s
Sample Input 2 4
Sample Output 7
Analysis:
Return the condition, if k=1, can only divide a
If k=n, each put one, there is only one case.
For each group of N, K:
The first case: first extract an element A, the rest of the n-1 elements of the Set division, and then put the element a into a set, and then because of this element a a total K species, so the total number of methods is k*s (N-1,K)
The second case: The element A is put into a separate set, the rest of the set division, so the master s (n-1,k-1)
Above ~
The recursive programming practice of Ka part3| set Division