Cod sursa(job #2042568)

Utilizator VladTiberiuMihailescu Vlad Tiberiu VladTiberiu Data 18 octombrie 2017 20:09:17
Problema Numerele lui Stirling Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

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

const int NMax = 203;

int stir1[NMax][NMax],stir2[NMax][NMax];
int x,n,m,t;

int main()
{
    f >> t;
    stir1[1][1] = 1;
    stir2[1][1] = 1;
    for(int i = 1; i <= NMax - 2; ++i){
        for(int j = 1; j <= NMax - 2; ++j){
            if(i == 1 && j == 1)
                continue;
            stir1[i][j] = stir1[i - 1][j - 1] - (i - 1) * stir1[i - 1][j];
            stir2[i][j] = stir2[i - 1][j - 1] + j * stir2[i - 1][j];
        }
    }
    while(t--){
        f >> x >> n >> m;
        if(x == 1){
            g << stir1[n][m] << '\n';
        }else{
            g << stir2[n][m] << '\n';
        }
    }
    return 0;
}