HDU2512 Cartoon Adventure "Stirling number, Bell number"

Source: Internet
Author: User

Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=2512


Main topic:

There are n cards, the n card is divided into several different sets, the collection cannot be empty. Q: How many kinds of sub-methods are there altogether?


Ideas:

Reference post: http://blog.csdn.net/acm_cxlove/article/details/7857671

The number of collections can be 1, 2, 3 、...、 N. The problem changed to put n cards in the I set.

This time a combinatorial problem can be solved with the second type of Stirling number.

S (p,k) = S (p-1,k-1) + k*s (p-1,k);

Represents the number of elements of p that are placed in a K-indistinguishable set and not empty.

The solution of the problem is: Σs (P,i), (1 <= i <= P). This number becomes the bell number.

The bell number is the number of divisions of the P-element set into non-null and indistinguishable examples.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;int Stir[2010][2010],bell[2010];int Main () {for    (int i = 1; i <=; ++i)        stir[i][1] = stir[i][i] = 1;
   
    for (int i = 2; I <=; ++i)    {for        (int j = 2; J <= i; ++j)            stir[i][j] = (Stir[i-1][j-1] + stir[i-1][j ]*J)%1000;    }    for (int i = 1; I <=, ++i) for        (int j = 1; J <= i; ++j)            bell[i] =  (Bell[i] + stir[i][j])% 1000;
    int n,t;    Cin >> T;    while (t--)    {        cin >> N;        cout << Bell[n] << Endl;    }    return 0;}
   


HDU2512 Cartoon Adventure "Stirling number, Bell number"

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.