Pagini recente » Cod sursa (job #2961555) | Cod sursa (job #1471096) | Cod sursa (job #700804) | Cod sursa (job #721980) | Cod sursa (job #3169792)
#include <iostream>
#include <fstream>
#define MODULO 98999
#define N_MAX 201
using namespace std;
ifstream in ("stirling.in");
ofstream out ("stirling.out");
int querries, x, n, m;
int matI[N_MAX][N_MAX], matII[N_MAX][N_MAX];
void spetaI (){
matI[0][0] = 1;
for (int i=1; i<N_MAX; ++i){
for (int j=1; j<=i; ++j){
if (i==1 && j == 1)
matI[i][j] = 1;
else if (i == j)
matI[i][j] = 1;
else {
matI[i][j] = (matI[i-1][j-1] + (i-1) * matI[i-1][j]) % MODULO;
}
// if ((i - j) % 2 == 1) // este impar
// matI[i][j] = -matI[i][j];
}
}
}
void spetaII (){
matII[0][0] = 1;
for (int i=1; i<N_MAX; ++i){
for (int j=1; j<=i; ++j){
if (i==1 && j == 1)
matII[i][j] = 1;
else if (i == j)
matII[i][j] = 1;
else {
matII[i][j] = (matII[i-1][j-1] + j * matII[i-1][j]) % MODULO;
}
}
}
}
int main (){
in >> querries;
spetaI();
spetaII();
for (int i=1; i<=querries; ++i){
in >> x >> n >> m;
if (x == 1){
if ((n-m) % 2 == 1)
out << -matI[n][m] << '\n';
else
out << matI[n][m] << '\n';
}
else
out << matII[n][m] << '\n';
}
return 0;
}