Pagini recente » Cod sursa (job #637100) | Cod sursa (job #2177121) | Cod sursa (job #1941890) | Cod sursa (job #577673) | Cod sursa (job #972534)
Cod sursa(job #972534)
#include <fstream>
#define mod 98999
#define nmax 200
using namespace std;
ifstream fin ("stirling.in");
ofstream fout ("stirling.out");
int s1[nmax+1][nmax+1],s2[nmax+1][nmax+1],T,n,m,kind;
void Stirling_first_kind (int n)
{
s1[0][0]=1;
for (int i=1; i<=n; i++)
for (int j=1; j<=i; j++)
s1[i][j] = (s1[i-1][j-1] - (i-1)*s1[i-1][j]) % mod;
}
void Stirling_second_kind (int n)
{
s2[0][0]=1;
for (int i=1; i<=n; i++)
for (int j=1; j<=i; j++)
s2[i][j] = (s2[i-1][j-1] + j*s2[i-1][j]) % mod;
}
int main ()
{
fin>>T;
Stirling_first_kind (nmax);
Stirling_second_kind (nmax);
for (int i=1; i<=T; i++)
{
fin>>kind>>n>>m;
if (kind==1) fout<<s1[n][m];
else fout<<s2[n][m];
fout<<"\n";
}
}