The recursive programming practice of Ka part3| set Division

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.