Cod sursa(job #3342634)

Utilizator Alex_at_gameIustin-Alexandru Frateanu Alex_at_game Data 25 februarie 2026 09:23:20
Problema Numerele lui Stirling Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.18 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(v) begin(v), end(v)
#define al(v, l, r) begin(v) + l, begin(v) + r + 1
#define sz(v) (int)v.size()
#define pb push_back
#define pob pop_back
#define fs first
#define sd second

constexpr int inf = 2e9;
constexpr ll infll = 4e18;
constexpr int mod = 98999;

ll stirling[2][205][205];

void prec() {
    stirling[0][1][1] = stirling[1][1][1] = 1;
    for (int n = 1; n <= 200; ++n) {
        for (int m = 1 + (n == 1); m <= n; ++m) {
            stirling[0][n][m] = (stirling[0][n - 1][m - 1] - ((n - 1) * stirling[0][n - 1][m]) % mod) % mod;
            stirling[1][n][m] = (stirling[1][n - 1][m - 1] + (m * stirling[1][n][m - 1]) % mod) % mod;
        }
    }
}

void solve() {
    int x, n, m;
    cin >> x >> n >> m;
    x--;
    cout << stirling[x][n][m] << "\n";
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    freopen("stirling.in", "r", stdin);
    freopen("stirling.out", "w", stdout);

    prec();

    int t;
    cin >> t;

    do {
        solve();
    } while (--t);
}