Cod sursa(job #2042573)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 18 octombrie 2017 20:18:38
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>

#define ll long long
using namespace std;
ifstream f("stirling.in");
ofstream g("stirling.out");

const ll NMax = 203;
const ll mod = 98999;

ll stir1[NMax][NMax],stir2[NMax][NMax];
ll x,n,m,t;

int main()
{
    f >> t;
    stir1[1][1] = 1;
    stir2[1][1] = 1;
    for(ll i = 1; i <= NMax - 2; ++i){
        for(ll j = 1; j <= NMax - 2; ++j){
            if(i == 1 && j == 1)
                continue;
            stir1[i][j] = (stir1[i - 1][j - 1] - (i - 1) * stir1[i - 1][j]);
            stir1[i][j] %= mod;
            stir2[i][j] = stir2[i - 1][j - 1] + j * stir2[i - 1][j];
            stir2[i][j] %= mod;
        }
    }
    while(t--){
        f >> x >> n >> m;
        if(x == 1){
            g << stir1[n][m] << '\n';
        }else{
            g << stir2[n][m] << '\n';
        }
    }
    return 0;
}