Cod sursa(job #1156719)

Utilizator tudgal1001Profir Tudor tudgal1001 Data 27 martie 2014 22:08:28
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include<cstdio>
#define modulo 98999
#define NMax 205
using namespace std;

int s[NMax][NMax],S[NMax][NMax];

void stirling1 ()
{
    int i,j;
    s[0][0]=1;
    for (i=1; i<=200; i++)
        for (j=1; j<=200; j++)
            s[i][j]=(s[i-1][j-1]-(i-1)*s[i-1][j])%modulo;
}

void stirling2 ()
{
    int i,j;
    S[0][0]=1;
    for (i=1; i<=200; i++)
        for (j=1; j<=200; j++)
            S[i][j]=(S[i-1][j-1]+j*S[i-1][j])%modulo;
}

int main ()
{
    int T,tip,N,K;
    freopen("stirling.in","r",stdin);
    freopen("stirling.out","w",stdout);
    stirling1();
    stirling2();
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d%d",&tip,&N,&K);
        if (tip==1)
            printf("%d\n",s[N][K]);
        else
            printf("%d\n",S[N][K]);
    }
    return 0;
}