Cod sursa(job #2070900)

Utilizator FredyLup Lucia Fredy Data 20 noiembrie 2017 00:03:04
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

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

#define lim 203
#define mod 98999
int stir1[lim][lim], stir2[lim][lim];
int x,n,m,t;

int main()
{
    fin>>t;
    stir1[1][1] = 1;
    stir2[1][1] = 1;
    for (int i=1; i<=lim-2; i++)
        for (int j=1; j<=lim-2; j++)
        {
            if (i==1 && j==1)
                continue;
            stir1[i][j] = stir1[i - 1][j - 1] - (i - 1) * stir1[i - 1][j];
            stir1[i][j] %= mod;
            stir2[i][j] = stir2[i - 1][j - 1] + j * stir2[i - 1][j];
            stir2[i][j] %= mod;
        }

    while(t--)
    {
        fin>>x>>n>>m;
        if(x == 1)
            fout<<stir1[n][m]<<'\n';
        else
            fout<<stir2[n][m]<<'\n';
    }
    return 0;
}