Fzu 1570 set division problem (number of bell)

Source: Internet
Author: User

BellNumber, also known as Bell number.

Eric temple bell is the name of Eric temple bell.

B (n) is the number of division methods for a set containing n elements.

B (0) = 1, B (1) = 1, B (2) = 2, B (3) = 5,

B (4) = 15, B (5) = 52, B (6) = 203 ,...

 

Recursive Formula,

B (0) = 1,

B (n + 1) = sum (0, n) C (n, k) B (k). n = 1, 2 ,...

Sum (0, n) indicates the sum of K from 0 to N, C (n, k) = n! /[K! (N-k)!]

Question: fzu 1570 set Division

Accept: 207 submit: 581
Time Limit: 1000 msec memory limit: 32768 kb Problem Description

A set of n elements {1, 2,..., n} can be divided into several non-empty subsets. For example, when n = 4, the set {1, 2, 3, 4} can be divided into 15 different non-empty subsets as follows:

 {{1},{2},{3},{4}},{{1,2},{3},{4}},{{1,3},{2},{4}},{{1,4},{2},{3}},{{2,3},{1},{4}},{{2,4},{1},{3}},{{3,4},{1},{2}},{{1,2},{3,4}},{{1,3},{2,4}},{{1,4},{2,3}},{{1,2,3},{4}},{{1,2,4},{3}},{{1,3,4},{2}},{{2,3,4},{1}},{{1,2,3,4}}

Given a positive integer N (1 <= n <= 20), calculate the number of different non-empty subsets of the set of n elements {,..., n.

Input Multiple groups of input data. one row of each group of data indicates the number of elements N. Output outputs one row for each group of data, indicating the number of different non-empty subsets. Sample input2 4 sample output2 15 // I feel that I am not writing recursive Programs... I want to practice well ,, # Include <iostream> <br/> using namespace STD; <br/> unsigned _ int64 C (int n, int m) <br/>{< br/> If (M> n/2) M = N-m; <br/> int I; <br/> unsigned _ int64 A = 1, B = 1; <br/> for (I = N; I> N-m; I --) <br/> A * = I; <br/> for (I = 2; I <= m; I ++) <br/> B * = I; <br/> return a/B; <br/>}< br/> unsigned _ int64 Bell (INT N) <br/>{< br/> unsigned _ int64 T = 0; <br/> int I; <br/> If (n = 0) return 1; <br/> else <br/> {<br/> for (I = 0; I <= n-1; I ++) <br/> T + = C (n-1, I) * Bell (I); <br/>}< br/> return t; <br/>}< br/> int main () <br/>{< br/> int N; <br/> while (scanf ("% d", & N )! = EOF) <br/> printf ("% i64u/N", Bell (n); <br/> return 0; <br/>}

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.