Pagini recente » Cod sursa (job #107723) | Cod sursa (job #485663) | Cod sursa (job #779453) | Cod sursa (job #2610610) | Cod sursa (job #3233258)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
const int MOD = 98999;
const int MAXN = 201; // maximum value for n and m based on the problem statement
vector<vector<int>> stirling_first(MAXN, vector<int>(MAXN, 0));
vector<vector<int>> stirling_second(MAXN, vector<int>(MAXN, 0));
void compute_stirling_numbers() {
stirling_first[0][0] = 1;
stirling_second[0][0] = 1;
for (int n = 1; n < MAXN; ++n) {
for (int m = 1; m <= n; ++m) {
stirling_first[n][m] = (stirling_first[n-1][m-1] + (n-1) * stirling_first[n-1][m] % MOD) % MOD;
stirling_second[n][m] = (stirling_second[n-1][m-1] + m * stirling_second[n-1][m] % MOD) % MOD;
}
}
}
int main() {
ifstream infile("stirling.in");
ofstream outfile("stirling.out");
int T;
infile >> T;
compute_stirling_numbers();
while (T--) {
int x, n, m;
infile >> x >> n >> m;
if (x == 1) {
outfile << stirling_first[n][m] << endl;
} else {
outfile << stirling_second[n][m] << endl;
}
}
infile.close();
outfile.close();
return 0;
}