Cod sursa(job #1058417)

Utilizator kitzTimofte Bogdan kitz Data 15 decembrie 2013 15:15:21
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#define MOD 98999
#define SIZE 201

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

int n, m, s[SIZE][SIZE], S[SIZE][SIZE];
int t;

int main(){
	s[1][1] = 1;
	for(int i = 2; i < SIZE; i++)
		for(int j = 1; j <= i; j++)
			s[i][j] = (s[i-1][j-1] - (i - 1) * s[i-1][j]) % MOD;
	S[1][1] = 1;
	for(int i = 2; i < SIZE; i++)
		for(int j = 1; j <= i; j++)
			S[i][j] = (S[i-1][j-1] + j * S[i-1][j]) % MOD;

	fin >> t;
	while( t != 0){
		int x, n, m;
		fin >> x >>n >> m;
		if(x == 1) fout << s[n][m] << "\n";
		else fout << S[n][m] << "\n";
		t--;
	}
	fout.close();
	return 0;
}