Cod sursa(job #2054806)

Utilizator FrequeAlex Iordachescu Freque Data 2 noiembrie 2017 16:11:01
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMAX = 200 + 5;
const int MOD = 98999;

int teste, cod, x, y;
int sp1[NMAX][NMAX], sp2[NMAX][NMAX];

int speta1(int n, int m)
{
    sp1[1][1] = 1;
    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            sp1[i][j] = (sp1[i - 1][j - 1] - (i - 1) * sp1[i - 1][j]) % MOD;
}

int speta2(int n, int m)
{
    sp2[1][1] = 1;
    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            sp2[i][j] = (sp2[i - 1][j - 1] + j * sp2[i - 1][j]) % MOD;
}

int main()
{
    fin >> teste;

    speta1(NMAX - 2, NMAX - 2);
    speta2(NMAX - 2, NMAX - 2);

    while (teste--)
    {
        fin >> cod >> x >> y;
        if (cod == 1)
            fout << sp1[x][y] << '\n';
        else
            fout << sp2[x][y] << '\n';
    }

    return 0;
}