Cod sursa(job #1900206)

Utilizator MotoAMotoi Alexandru MotoA Data 3 martie 2017 10:53:55
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("stirling.in");
ofstream g("stirling.out");
const int MOD = 98999;
int stir2[202][202], stir1[202][202];
void stirling2(int n) {
    int i, j;
    stir2[0][0] = 1;
    for(i = 1; i <= n; i++) {
        stir2[i][1] = 1;
        stir2[i][i]=1;
        for(j = 2; j < i; j++)
            stir2[i][j] = (j * stir2[i - 1][j] + stir2[i - 1][j - 1]) % MOD;
    }
}
void stirling1(int n) {
    int i, j;
    stir1[0][0] = 1;
    for(i = 1; i <= n; i++) {
        stir1[i][i] = 1;
        for(j = 1; j < i; j++)
            stir1[i][j] = (stir1[i - 1][j - 1] - (i - 1) * stir1[i - 1][j]) % MOD;
    }
}
int main() {
    int T,s,k,n;
    f >> T;
    stirling1(200);
    stirling2(200);
    /*
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++)
            cout << stir1[i][j] << ' ';
        cout << endl;
    }*/
    while(T--){
     f>>s>>k>>n;
     if(s==1)g<<stir1[k][n]<<'\n';
      else g<<stir2[k][n]<<'\n';
    }
    return 0;
}