Cod sursa(job #2857273)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 25 februarie 2022 11:00:09
Problema Numerele lui Stirling Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("stirling.in");
ofstream g("stirling.out");

int s1[205][205],s2[205][205];
int c,n,m,t;

int main()
{
    s1[0][0]=1;
    for (int i=1;i<=200;i++) {
        for (int j=1;j<=200;j++) {
            s1[i][j] = s1[i-1][j-1]+j*s1[i-1][j];
        }
    }
    s2[0][0]=1;
    for (int i=1;i<=200;i++) {
        for (int j=1;j<=200;j++) {
            s2[i][j] = s2[i-1][j-1] - (i-1)*s2[i-1][j];
        }
    }
    f >> t;
    for (int i=1;i<=t;i++) {
        f >> c >> n >> m;
        if (c==1) {
            g << s2[n][m] << '\n';
        }
        else g << s1[n][m] << '\n';
    }
    return 0;
}