Cod sursa(job #3196178)

Utilizator luc3lexaAlexandrescu Luca luc3lexa Data 22 ianuarie 2024 23:59:55
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
int n,x,y,t,tip;
const int nmax = 210,kmax = 210,MOD = 98999;
vector<vector<long long int>> stirling1(nmax+1,vector<long long int>(kmax+1)),stirling2(nmax+1,vector<long long int>(kmax+1));
void precalculare(){
    stirling1[0][0] = stirling2[0][0] = 1;
    for(int i = 1; i <=nmax; i++){
        for(int j = 1; j <= min(i,kmax); j++){
            stirling1[i][j] = (stirling1[i-1][j-1] - (i-1)*stirling1[i-1][j]%MOD)%MOD;
        }
    }
    for(int i = 1; i <=nmax; i++){
        for(int j = 1; j <= min(i,kmax); j++){
            stirling2[i][j] = (stirling2[i-1][j-1] +  j*stirling2[i-1][j]%MOD)%MOD;
        }
    }
};

void solve(){
   fin >> tip >> x >> y;
   if(tip == 1){
    fout << stirling1[x][y] << '\n';
   }else{
   fout << stirling2[x][y] << '\n';}
}
int main()
{
   fin >> t;
   precalculare();
   while(t--){
    solve();
   }
}