Title DescriptionDescription S is a set of n elements, S={a1,a2,......,an}, which now divides s into K, a subset of S1,S2,......,SK satisfying the following conditions, and satisfies:It is said that S1,s2,......,sk is a division of set S. It is equivalent to the N elements in the S collection A1, A2,......,an into K (0
input/output format input/output
Input Format:
A positive integer k.
output Format:
A positive integer n.
input and Output sample sample Input/output
sample Test point # #
Input Sample:23 7
Sample output:4382641999117305 ideas: First of all, for example, set s={1,2,3,4},k=3, it is not difficult to conclude that S has 6 different partitioning schemes, that is, the number of S (4,3) = 6, the specific scheme is:{1,2}∪{3}∪{4} {1,3}∪{2}∪{4} {1,4}∪{2}∪{3}{2,3}∪{1}∪{4} {2,4}∪{1}∪{3} {3,4}∪{1}∪{2} Consider the general situation, For any of the N-element A1, A2,......,an's set of S, into the K-unlabeled box, divided by the number of S (n,k), it is difficult for us to rely on intuition and experience to calculate the division number and enumeration of all the schemes, we must sum up the nature of the problem. In fact, for any of the elements of an, it is inevitable that the following two cases: 1, {an} is a K subset, so we just divide the a1,a2,......,an-1 into subsets of K-1, it solves the problem, in this case the division of the number of a total of S (n-1,k-1); 2. {An} is not one of the K-subsets, then an must form a subset of its elements. The problem is the equivalent of dividing the a1,a2,......,an-1 into k subsets, in which case the fractional total is S (n-1,k), and then the element an is added to any of the K-subgroups, a total of K-joins, so that for each of the joining methods, the set can be divided into k subsets, Therefore, according to the multiplication principle, divides the number altogether K * S (N-1,K) to synthesize above two kinds of cases, applies the addition principle, obtains the N element's set {A1,a2,......,an} divides into the K subset the dividing number is the following recursive formula: S (n,k) =s (n-1,k-1) + K * S (N-1,K) (n>k,k>0). Below, we determine the boundary condition of S (n,k), first can not put n elements in any one of the set, namely K=0, S (n,k) = 0, it is also impossible to not allow empty boxes to put n elements in more than K set of N, that is, K>n, S (n,k) = 0; Put n elements into a set or n elements into n sets, the scheme number is obviously 1, that is, k=1 or K=n, S (n,k) = 1. Therefore, we can conclude that the recursive relationship of number S (n,k) is: s (n,k) =s (n-1,k-1) + K * S (n-1,k) (n>k,k>0) s (n,k) =0 (n<k) or (k=0) S (n,k) =1 (k=1) or (k=n)
The code is as follows:
1#include <stdio.h>2 intJihe (intNintK//data may also be out of bounds, please calculate with high accuracy3 {4 if((n<k) | | (k==0))return 0;5 Else if((k==1)|| (k==n))return 1;6 Else returnJihe (n1, K-1) +k*jihe (n1, K); 7 }8 intMain ()9 {Ten intn,k; Onescanf"%d%d",&n,&k); Aprintf"%d\n", Jihe (n,k)); - return 0; -}
Division of a set