Pagini recente » Cod sursa (job #3292356) | Diferente pentru schimbare-borland/alternativa intre reviziile 10 si 13 | Ecuatie | Cod sursa (job #3258232) | Cod sursa (job #3241504)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("stirling.in");
ofstream g("stirling.out");
int stir[201][201];
void stirling1(int n, int k)
{
int i, j;
stir[0][0] = 1;
for(i = 1; i <= n; ++i)
for(j = 1; j <= min(i, k); ++j)
stir[i][j] = stir[i - 1][j - 1] + (i - 1) * stir[i - 1][j];
g << stir[n][k];
}
void stirling2(int n, int k)
{
int i, j;
stir[0][0] = 1;
for(i = 1; i <= n; ++i)
for(j = 1; j <= min(i, k); ++j)
stir[i][j] = stir[i - 1][j - 1] + j * stir[i - 1][j];
g << stir[n][k];
}
int main()
{
int T, x, n, k;
f >> T;
while(T--)
{
f >> x >> n >> k;
if(x == 1)
stirling1(n, k);
else
stirling2(n, k);
g << '\n';
}
f.close();
g.close();
return 0;
}