Cod sursa(job #544426)

Utilizator avram_florinavram florin constantin avram_florin Data 1 martie 2011 16:32:56
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include<fstream>

using namespace std;

const int MaxN = 201;
const int Mod = 98999;

int T,speta,n,m,s[MaxN][MaxN],S[MaxN][MaxN];

void precalculare()
{
	int i,j;
	S[1][1] = s[1][1] = 1;
	for( i = 2 ; i < MaxN ; ++i )
		for( j = 1 ; j <= i ; ++j )
			{
				s[i][j] = (s[i-1][j-1] - (i-1)*s[i-1][j]) % Mod;
				S[i][j] = (S[i-1][j-1] + j*S[i-1][j]) % Mod;
			}
}

int main()
{
	ifstream f ("stirling.in");
	ofstream g ("stirling.out");
	precalculare();
	f >> T;
	while (T-- )
		{
			f >> speta >> n >> m;
			if( speta == 1)
				g << s[n][m] << '\n';
				else
				g << S[n][m] << '\n';
		}
	f.close();
	g.close();
	return 0;
}