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)