Cod sursa(job #2465509)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 30 septembrie 2019 11:11:43
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

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

const int DIM = 200;
const int MOD = 98999;

int s1[DIM + 5][DIM + 5], s2[DIM + 5][DIM + 5];

int main()
{
    s1[1][1] = s2[1][1] = 1;

    for(int i = 2; i <= DIM; i++)
        for(int j = 1; j <= i; j++)
        {
            s1[i][j] = (s1[i - 1][j - 1] - (i - 1) * s1[i - 1][j]) % MOD;
            s2[i][j] = (s2[i - 1][j - 1] + j * s2[i - 1][j]) % MOD;
        }

    int T;
    fin >> T;

    while(T--)
    {
        int t, x, y;
        fin >> t >> x >> y;

        if(t == 1) fout << s1[x][y] << '\n';
        else fout << s2[x][y] << '\n';
    }

    return 0;
}