Cod sursa(job #3317265)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 22 octombrie 2025 22:40:16
Problema Numerele lui Stirling Scor 20
Compilator cpp-64 Status done
Runda cex_02 Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("stirling.in");
ofstream fout("stirling.out");
const int MAX = 200;
int q, i, j, stir[2][MAX + 2][MAX + 2];

int main() {
    fin.tie(NULL);
    fout.tie(NULL);

    stir[0][0][0] = 1;
    stir[1][0][0] = 1;
    for(i = 1; i <= MAX; i++) {
        for(j = 1; j <= i; j++) {
            stir[0][i][j] = stir[0][i - 1][j - 1] +  j      * stir[0][i - 1][j];
            stir[1][i][j] = stir[1][i - 1][j - 1] - (i - 1) * stir[1][i - 1][j];
        }
    }
    fin >> q;
    while(q--) {
        fin >> i;
        if(i == 1) {
            fin >> i >> j;
            fout << stir[1][i][j] << "\n";
        }
        else {
            fin >> i >> j;
            fout << stir[0][i][j] << "\n";
        }
    }

    return 0;
}