Cod sursa(job #3241504)

Utilizator raulthestormIlie Raul Ionut raulthestorm Data 30 august 2024 22:09:48
Problema Numerele lui Stirling Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int stir[201][201];

void stirling1(int n, int k)
{
    int i, j;
    stir[0][0] = 1;
    for(i = 1; i <= n; ++i)
        for(j = 1; j <= min(i, k); ++j)
            stir[i][j] = stir[i - 1][j - 1] + (i - 1) * stir[i - 1][j];
    g << stir[n][k];
}

void stirling2(int n, int k)
{
    int i, j;
    stir[0][0] = 1;
    for(i = 1; i <= n; ++i)
        for(j = 1; j <= min(i, k); ++j)
            stir[i][j] = stir[i - 1][j - 1] + j * stir[i - 1][j];
    g << stir[n][k];
}

int main()
{
    int T, x, n, k;
    f >> T;
    while(T--)
    {
        f >> x >> n >> k;
        if(x == 1)
            stirling1(n, k);
        else
            stirling2(n, k);
        g << '\n';
    }
    f.close();
    g.close();
    return 0;
}