Cod sursa(job #2373662)

Utilizator PandaChanTrusca Daria PandaChan Data 7 martie 2019 14:45:03
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
#define MOD 98999;
using namespace std;
ifstream f("stirling.in");
ofstream g("stirling.out");
int s[205][205], S[205][205];
int x, n, m;
void speta1()
{
    s[0][0]=1;
    s[1][1]=1;
    for(int x=1; x<=200; x++)
        for(int y=x; y>0; y--)
            s[x][y]=(s[x-1][y-1]-(x-1)*s[x-1][y])%MOD;
}
void speta2()
{
    S[1][1]=1;
    S[0][0]=1;
    for(int x=1; x<=200; x++)
        for(int y=x; y>0; y--)
            S[x][y]=(S[x-1][y-1]+y*S[x-1][y])%MOD;
}
int main()
{
    int t;
    f>>t;
    speta2();
    speta1();
    for(int i=0; i<t; i++)
    {
        f>>x>>n>>m;
        if(x==2)
            g<<S[n][m]<<endl;
        else
            g<<s[n][m]<<endl;
    }
    return 0;
}