Cod sursa(job #1542959)

Utilizator sebinechitasebi nechita sebinechita Data 5 decembrie 2015 20:41:57
Problema Numerele lui Stirling Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
#define MAX 210
#define MOD 98999
int s1[MAX][MAX], s2[MAX][MAX];

int main()
{
    int t, i, j, n = 200, x, y, z;
    s1[1][1] = 1;
    s2[1][1] = 1;
    for(i = 2 ; i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            s1[i][j] = ((s1[i - 1][j - 1] + (1 - i) * s1[i - 1][j]) % MOD - MOD) % MOD;
            s2[i][j] = (s2[i - 1][j - 1] + j * s2[i - 1][j]) % MOD;
        }
    }
    fin >> t;
    while(t--)
    {
        fin >> x >> y >> z;
        if(x == 1)
        {
            fout << s1[y][z] << "\n";
        }
        else
        {
            fout << s2[y][z] << "\n";
        }
    }
}