Pagini recente » Cod sursa (job #1765617) | Cod sursa (job #2802224) | Cod sursa (job #2235346) | Cod sursa (job #435180) | Cod sursa (job #3344873)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
const int MOD = 98999;
long long stirling_1(int N, int K) {
vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = (dp[i - 1][j - 1] + (i - 1) * dp[i - 1][j] % MOD) % MOD;
}
}
return dp[N][K];
}
long long stirling_2(int N, int K) {
vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = (dp[i - 1][j - 1] + j * dp[i - 1][j] % MOD) % MOD;
}
}
return dp[N][K];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ifstream cin{"stirling.in"};
ofstream cout{"stirling.out"};
int tc;
cin >> tc;
while (tc--) {
int c, a, b;
cin >> c >> a >> b;
int ok = 1;
if (a > b) {
swap(a, b);
ok = -1;
}
long long res = 0;
if (c == 1) {
res = stirling_1(a, b);
} else
res = stirling_2(a, b);
res *= ok;
cout << res << '\n';
}
return 0;
}