Cod sursa(job #3157372)

Utilizator ph1lippejourdheuilJourdheuil Philippe ph1lippejourdheuil Data 15 octombrie 2023 14:18:22
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");
int n, st[220][220], stsp2[220][220], m, t, x, mod=98999;

void stirling()
{
    for (int i=2; i<=200; i++)
    {
        for (int j=1; j<=i; j++)
        {
            st[i][j]=(st[i-1][j-1]-(i-1)*st[i-1][j])%mod;
        }
    }
}

void stirlingspII()
{
    for (int i=2; i<=200; i++)
    {
        for (int j=1; j<=i; j++)
        {
            stsp2[i][j]=(stsp2[i-1][j-1]+j*stsp2[i-1][j])%mod;
        }
    }
}

int main()
{
    st[1][1]=1;
    stsp2[1][1]=st[1][1];
    fin >> t;
    stirling();
    stirlingspII();
    for (int i=1; i<=t; i++)
    {
        fin >> x >> n >> m;
        if (x==1)
        {
           fout << st[n][m] << '\n';
        }
        else fout << stsp2[n][m] << '\n';
    }

    fin.close();
    fout.close();
    return 0;
}