Pagini recente » Diferente pentru warm-up-2019/solutii/shoturi intre reviziile 38 si 37 | Monitorul de evaluare | Cod sursa (job #1654976) | Cod sursa (job #2036040) | Cod sursa (job #1900206)
#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;
}