[ACM] SDUT 2883 hearthur Stone II (second class Stiring number)

Source: Internet
Author: User
Tags integer numbers

Hearthur Stone IITime Limit: 2000 ms Memory limit: 65536 K Any Questions? Click here ^_^The new season has begun, you have n competitions and m well prepared decks during the new season. each competition you cocould use any deck you want, but each of the decks must be used at least once. now you wonder how many ways are there to plan the season-to decide for each competition which deck you are going to used. the number can be very huge, mod it with 10 ^ 9 + 7. input The input? Le contains several test cases, one line for each case contains two integer numbers n and m (1? ≤? M? ≤? N? ≤? 100). output One line for each case, output one number-the number of ways. Example input
3 2100 25
Sample output
6354076161
Tip: 2014 Shandong fifth ACM College student program design competition


Solution:

M tables are used for n competitions. Each table is used at least once. The tables are different. How many ways are there to arrange.

That is, to divide n elements into m non-empty and non-differentiated sets. The second type of Stiring number s (n, m) means to divide n elements into m non-empty and non-differentiated sets. The answer to this question set (table) is yes

M! * S (n, m ).

Knowledge details see: http://blog.csdn.net/sr_19930829/article/details/40888349

Code:

# Include <iostream> # include <string. h> using namespace std; const int maxn = 102; const int mod = 1e9 + 7; typedef long ll; ll s [maxn] [maxn]; int n, m; void init () {memset (s, 0, sizeof (s); s [1] [1] = 1; for (int I = 2; I <= 100; I ++) for (int j = 1; j <= I; j ++) {s [I] [j] = s [i-1] [j-1] + j * s [i-1] [j]; if (s [I] [j]> = mod) s [I] [j] % = mod;} ll solve (int n, int m) {ll ans = s [n] [m]; for (int I = 2; I <= m; I ++) {ans * = I; if (ans> = mod) ans % = mod;} return ans ;} int main () {init (); while (cin> n> m) {cout <solve (n, m) <endl ;}return 0 ;}



[ACM] SDUT 2883 hearthur Stone II (second class Stiring 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.