Cod sursa(job #1026854)

Utilizator sebinechitasebi nechita sebinechita Data 12 noiembrie 2013 08:37:37
Problema Numerele lui Stirling Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("stirling.in");
ofstream fout("stirling.out");

#define MAX 210

int a[MAX][MAX],b[MAX][MAX],i,j,n,m,x,c,d;

void make_matrix1()
{
    a[0][0]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            a[i][j]=a[i-1][j-1]-(i-1)*a[i-1][j];
        }
    }
}

void make_matrix2()
{
    b[0][0]=1;
    for(i=1;i<=n;i++)
    {
        b[i][1]=b[i][i]=1;
    }

    for(i=2;i<=n;i++)
    {
        for(j=2;j<i;j++)
        {
            b[i][j]=(j)*b[i-1][j]+b[i-1][j-1];
        }
    }
}


int main()
{
    n=m=202;
    make_matrix1();
    make_matrix2();
    int t,ki;
    fin>>t;
    for(ki=1;ki<=t;ki++)
    {
        fin>>x;
        fin>>c>>d;
        if(x==1)
        {
            fout<<a[c][d];
        }
        else
        {
            fout<<b[c][d];
        }
        fout<<"\n";
    }
    return 0;
}