Cod sursa(job #2768440)

Utilizator cyg_mihaizMIHAI ZARAFIU cyg_mihaiz Data 10 august 2021 18:42:47
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>

using namespace std;
const int MOD = 98999;
const int NMAX = 200;

ifstream fin("stirling.in");
ofstream fout("stirling.out");

int dp_speta1[NMAX + 5][NMAX + 5];
int dp_speta2[NMAX + 5][NMAX + 5];

int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);

    int t,i,j,sp,x,y;
    fin >> t;
    dp_speta1[1][1] = dp_speta2[1][1] = 1;
    for(i = 2; i <= NMAX; i++)
        for(j = 1; j <= i; j++)
        {
            dp_speta1[i][j] = (dp_speta1[i - 1][j - 1] - (i - 1) * dp_speta1[i - 1][j]) % MOD;
            dp_speta2[i][j] = (dp_speta2[i - 1][j - 1] + j * dp_speta2[i - 1][j]) % MOD;
        }
    while(t--)
    {
        fin >> sp >> x >> y;
        if(sp == 1)
            fout << dp_speta1[x][y] << "\n";
        else
            fout << dp_speta2[x][y] << "\n";
    }
    return 0;
}