Cod sursa(job #1346979)

Utilizator akaprosAna Kapros akapros Data 18 februarie 2015 18:24:44
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include<cstdio>
#include<algorithm>
#include<cstring>
#define Nmax 201
using namespace std;
int n,i,j,x,y,z,t;
int s[Nmax+5][Nmax+5],S[Nmax+5][Nmax+5];
void dp()
{
    for (i=2;i<=Nmax;i++)
    for (j=1;j<=i;j++)
    {
        s[i][j]=(s[(i-1)][j-1]-(i-1)*s[(i-1)][j])%98999;
        S[i][j]=(S[(i-1)][j-1]+j*S[(i-1)][j])%98999;
    }
}
int main()
{
    freopen("stirling.in","r",stdin);
    freopen("stirling.out","w",stdout);
    scanf("%d",&t);
    s[1][1]=S[1][1]=1;
    dp();
    while (t--)
    {
        scanf("%d %d %d",&x,&y,&z);
        if (x==1) printf("%d\n",s[y][z]);
        else printf("%d\n",S[y][z]);
    }
    return 0;
}