Cod sursa(job #2069418)

Utilizator theodor.vladTheodor Vlad theodor.vlad Data 18 noiembrie 2017 13:20:44
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>

using namespace std;
ifstream fin("stirling.in");
ofstream fout("stirling.out");

void stirlingI();
void stirlingII();

int s[202][202], S[202][202];

int main()
{
	int t;
	fin >> t;

	stirlingI();
	stirlingII();

	for (int i = 1; i <= t; i++)
	{
		int x, n, m;
		fin >> x >> n >> m;

		if (x == 1)
			fout << s[n][m] << '\n';
		else
			fout << S[n][m] << '\n';
	}
	return 0;
}

void stirlingI()
{
	s[1][1] = 1;
	for (int i = 2; i <= 200; i++)
		for (int j = 1; j <= i; j++)
			s[i][j] = (s[i - 1][j - 1] - (i - 1) * s[i - 1][j]) % 98999;
}

void stirlingII()
{
	S[1][1] = 1;
	for (int i = 2; i <= 200; i++)
		for (int j = 1; j <= i; j++)
			S[i][j] = (S[i - 1][j - 1] + j * S[i - 1][j]) % 98999;
}