Cod sursa(job #2700244)

Utilizator rARES_4Popa Rares rARES_4 Data 26 ianuarie 2021 21:25:33
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#define MOD 98999
using namespace std;
ifstream f ("stirling.in");
ofstream g ("stirling.out");
int triunghi1[205][205],triunghi2[205][205],t,k,n,c;
int stirling2kind()
{
    triunghi2[0][0] = 1;
    for(int i = 1;i<=201;i++)
    {
        for(int j = i;j>=0;j--)
        {
            triunghi2[i][j] = (triunghi2[i-1][j-1] + (j*triunghi2[i-1][j])%MOD)%MOD;
        }
    }
}
int stirling1kind()
{
    triunghi1[0][0] = 1;
    for(int i =1;i<=201;i++)
    {
        for(int j = i;j>=0;j--)
        {
            triunghi1[i][j] = (triunghi1[i-1][j-1] - ((i-1) * triunghi1[i-1][j])%MOD)%MOD;
        }
    }
}
int main()
{
    f >> t;
    stirling1kind();
    stirling2kind();
    for(int i = 1;i<=t;i++)
    {
        f >> c >> n >> k;
        if(c == 1)
            g << triunghi1[n][k]<<'\n';
        else
            g << triunghi2[n][k]<<'\n';
    }
}