Cod sursa(job #1665597)

Utilizator alin1999Buzatu Alin alin1999 Data 27 martie 2016 09:57:46
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
using namespace std;
const int N=201,mod=98999;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
int s[N][N],S[N][N],i,j,t,x,m,n;
void precalculares()
{
    s[1][1]=1;
    for(int i=2;i<N;i++)
        for(int j=1;j<=i;j++)
        s[i][j]=(s[i-1][j-1]-(i-1)*s[i-1][j])%mod;
}
void precalculareS()
{
    S[1][1]=1;
    for(int i=2;i<N;i++)
        for(int j=1;j<=i;j++)
        S[i][j]=(S[i-1][j-1]+j*S[i-1][j])%mod;
}
int main()
{
    fin>>t;
    precalculares();
    precalculareS();
    for(i=1;i<=t;i++)
    {
        fin>>x>>n>>m;
        if(x==1)
            fout<<s[n][m]<<endl;
        if(x==2)
            fout<<S[n][m]<<endl;
    }
    return 0;
}