Cod sursa(job #1929155)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 17 martie 2017 10:34:54
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

const int N = 2e2, Mod = 98999;

int tests, n, m, s[N+5][N+5], S[N+5][N+5], tip;

void stirling1()
{
    int i, j;
    s[0][0] = 1;
    for(i=1; i<=N; ++i) s[i][0] = s[0][i] = 0;

    for(i=1; i<=N; ++i)
        for(j=1; j<=N; ++j)
            s[i][j] = (s[i-1][j-1] - (i-1) * s[i-1][j]) % Mod;
}

void stirling2()
{
    int i, j;
    S[0][0] = 1;
    for(i=1; i<=N; ++i) S[i][0] = S[0][i] = 0;

    for(i=1; i<=N; ++i)
        for(j=1; j<=N; ++j)
            S[i][j] = (S[i-1][j-1] + j * S[i-1][j]) % Mod;
}

int main()
{
    stirling1(); stirling2();

    fin >> tests;
    while(tests--)
    {
        fin >> tip >> n >> m;
        fout << (tip==1 ? s[n][m] : S[n][m]) << '\n';
    }

    return 0;
}