Cod sursa(job #2971460)

Utilizator vladth11Vlad Haivas vladth11 Data 27 ianuarie 2023 13:54:40
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.3 kb
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const ll NMAX = 201;
const ll VMAX = 41;
const ll INF = (1LL << 30);
const ll MOD = 98999;
const ll BLOCK = 318;
const ll base = 31;
const ll nrbits = 21;

int stirling1[NMAX][NMAX];
int stirling2[NMAX][NMAX];

int main() {
    ifstream cin("stirling.in");
    ofstream cout("stirling.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i, j;
    stirling1[1][1] = 1;
    int n = NMAX - 1;
    for(i = 2; i <= n; i++){
        for(j = 1; j <= i; j++){
            stirling1[i][j] = (stirling1[i - 1][j - 1] - (1LL * (i - 1) * stirling1[i - 1][j]) % MOD) % MOD;
        }
    }
    stirling2[1][1] = 1;
    for(i = 2; i <= n; i++){
        for(j = 1; j <= i; j++){
            stirling2[i][j] = (stirling2[i - 1][j - 1] + 1LL * j * stirling2[i - 1][j]) % MOD;
        }
    }
    int q;
    cin >> q;
    while(q--){
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 1){
            cout << stirling1[a][b] << "\n";
        }else{
            cout << stirling2[a][b] << "\n";
        }
    }
    return 0;
}