Pagini recente » Cod sursa (job #1568691) | Cod sursa (job #3206035)
#include <bits/stdc++.h>
using namespace std;
#define INFILE "stirling.in"
#define OUTFILE "stirling.out"
const short SZ_MAX = 205;
const int MOD = 98999;
int s[SZ_MAX][SZ_MAX], S[SZ_MAX][SZ_MAX];
void init(){
s[0][0] = S[0][0] = 1;
for(int i = 1; i < SZ_MAX; ++i){
for(int j = 1; j < SZ_MAX; ++j){
s[i][j] = (s[i - 1][j - 1] - (i - 1) * s[i - 1][j] % MOD) % MOD;
S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j] % MOD) % MOD;
}
}
}
void solve_1(){
// ! Stirling Number of the First Kind
// ? Counts the number of permutations of n elements with m dijoint cycles
short n, m; cin >> n >> m;
cout << s[n][m] << '\n';
}
void solve_2(){
// ! Stirling Number of the Second Kind
// ? Counts the number of ways to partition a set of n elements into m nonempty subsets
short n, m; cin >> n >> m;
cout << S[n][m] << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
cin.tie(0), cout.tie(0);
init();
short tests; cin >> tests;
for(int i = 0; i < tests; ++i){
short task; cin >> task;
(task == 1 ? solve_1() : solve_2());
}
return 0;
}