Cod sursa(job #2973305)

Utilizator Luca_CristianZamfir Luca-Cristian Luca_Cristian Data 31 ianuarie 2023 18:29:49
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("stirling.in");
ofstream fout("stirling.out");
const int Nmax = 201, MOD = 98999;
vector <vector <int>> speta2(Nmax, vector <int> (Nmax)), speta1(Nmax, vector <int> (Nmax));

void calc2()
{

    int i, j;
    speta2[0][0] = 1;
    for(i = 1; i < Nmax; i++)
        for(j = 1; j < Nmax; j++)
            speta2[i][j] = (speta2[i - 1][j - 1] + j * speta2[i - 1][j]) % MOD;
}

void calc1()
{
    int i, j;
    speta1[1][1]= 1;
	for(i = 2; i < Nmax; i++)
		for(j = 1; j <= i; j++)
			speta1[i][j]= (speta1[i - 1][j - 1] - (i - 1) * speta1[i - 1][j]) % MOD ;
}


int main()
{
    int t, n, k;

    calc1(), calc2();
    fin >> t;
    for(int i = 1; i <= t; i++)
    {
        int tip;
        fin >> tip >> n >> k;

        if(tip == 2)
            fout << speta2[n][k];
        else
            fout << speta1[n][k];
        fout << '\n';
    }

    return 0;
}