Pagini recente » Cod sursa (job #2320975) | Cod sursa (job #3131709) | Cod sursa (job #2268059) | Cod sursa (job #2703607) | Cod sursa (job #2437419)
#include <iostream>
#include <fstream>
using namespace std;
void calculare_1(int s[100][100]){
s[1][1] = 1;
for(int i = 2; i < 100; i++){
for(int j = 1; j<=i; j++){
s[i][j] = ( s[i-1][j-1] - (i-1)*s[i-1][j]);
}
}
}
void calculare_2(int S[100][100]){
S[1][1] = 1;
for(int i = 2; i < 100; i++){
for(int j = 1; j<=i; j++){
S[i][j] = ( S[i-1][j-1] + j*S[i-1][j]);
}
}
}
int main(){
int n, m, x, t, s[100][100], S[100][100];
ifstream fin("stirling.in");
ofstream fout("stirling.out");
fin >> t;
calculare_1(s);
calculare_2(S);
for(int i = 0; i < t; i++){
fin >> x >> n >> m;
if(x == 1){
fout << s[n][m] << '\n';
}
if(x == 2){
fout << S[n][m] << '\n';
}
}
return 0;
}