Cod sursa(job #3357387)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 9 iunie 2026 10:47:12
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

#define USE_STD_IO 0
#if USE_STD_IO
    #define fin cin
    #define fout cout
#else
    ifstream fin("stirling.in");
    ofstream fout("stirling.out");
#endif

const int MOD = 98999;
const int MAX = 200;
int n, q, i, j;
int s[2][MAX + 2][MAX + 2];

int main() {
    #if USE_STD_IO
        ios_base::sync_with_stdio(false);
    #endif // USE_STD_IO
    fin.tie(NULL);
    fout.tie(NULL);

    s[0][0][0] = 1;
    s[1][0][0] = 1;
    for(i = 1; i <= MAX; i++) {
        for(j = 1; j <= i; j++) {
            s[0][i][j] = s[0][i - 1][j - 1];
            s[0][i][j] -= (i - 1) * s[0][i - 1][j] % MOD;
            s[0][i][j] %= MOD;

            s[1][i][j] = s[1][i - 1][j - 1];
            s[1][i][j] += j * s[1][i - 1][j];
            s[1][i][j] %= MOD;
        }
    }

    fin >> q;
    while(0 < q--) {
        int ss, n, m;
        fin >> ss >> n >> m;
        fout << s[ss - 1][n][m] << '\n';
    }

    return 0;
}