Cod sursa(job #3354855)

Utilizator nverde1119Popa Narcis Constantin nverde1119 Data 21 mai 2026 00:15:19
Problema Numerele lui Stirling Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <fstream>

using namespace std;
ifstream f("stirling.in");
ofstream g("stirling.out");
int s[201][201], S[201][201], n, m, x,T;
void prel()
{
	S[0][0] = s[0][0] = 1;
	for(int i = 1; i <= 200; i++)
	{
		for(int j = 1; j <= i; j++)
		{
			s[i][j] = -(i - 1) * s[i - 1][j] + s[i - 1][j - 1];
			S[i][j] = j * S[i - 1][j] + S[i - 1][j - 1];
		}
	}
}
int main()
{
	prel();
	f >> T;
	while(T--)
	{
		f >> x >> n >> m;
		if(x == 1)
			g << s[n][m] << '\n';
		else
			g << S[n][m] << '\n';
	}
	return 0;
}