Cod sursa(job #2377162)

Utilizator MarianConstantinMarian Constantin MarianConstantin Data 8 martie 2019 22:34:37
Problema Numerele lui Stirling Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <iostream>
#include <fstream>

using namespace std;

const int MAXN = 200, MOD = 98999;

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

int stiriling1[MAXN + 10][MAXN + 10], stiriling2[MAXN + 10][MAXN + 10];

void preprocess() {
    stiriling1[0][0] = 1;
    stiriling1[1][1] = 1;
    for (int i = 2; i <= MAXN; ++i)
        for (int j = 1; j <= i; ++j)
            stiriling1[i][j] = (1ll * stiriling1[i - 1][j - 1] - 1ll * (i - 1) * stiriling1[i - 1][j]) % MOD;
    stiriling2[0][0] = 1;
    stiriling2[1][1] = 1;
    for (int i = 2; i <= MAXN; ++i)
        for (int j = 1; j <= i; ++j)
            stiriling2[i][j] = (1ll * stiriling2[i - 1][j - 1] + 1ll * j * stiriling2[i - 1][j]) % MOD;
}

int main() {
    int t, x, y, nr;
    preprocess();
    fin >> t;
    for (int i = 0; i < t; ++i) {
        fin >> nr >> x >> y;
        if (nr == 1)
            fout << stiriling1[x][y] << "\n";
        else
            fout << stiriling2[x][y] << "\n";
    }
    cout << sizeof(stiriling1) * 2 / 1024;
    return 0;
}