Cod sursa(job #2667801)

Utilizator akumariaPatrascanu Andra-Maria akumaria Data 3 noiembrie 2020 21:09:04
Problema Numerele lui Stirling Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>

using namespace std;

#define MAXN 202
#define MOD 98999

int type_1[MAXN][MAXN], type_2[MAXN][MAXN];


void precalculate_type_1() {
	type_1[1][1] = 1;
	for(int i=2; i<MAXN; ++i)
		for(int j = 1; j<=i; ++j)
			type_1[i][j] = (type_1[i-1][j-1] - (i-1) * type_1[i-1][j]) % MOD;
}


void precalculate_type_2() {
	type_2[1][1] = 1;
	for(int i=2; i<MAXN; ++i)
		for(int j = 1; j<=i; ++j)
			type_2[i][j] = (type_2[i-1][j-1] + j * type_2[i-1][j]) % MOD;
}



int main() {
	freopen("stirling.in", "r", stdin);
	freopen("stirling.out", "w", stdout);

	int n, type, a, b;
	precalculate_type_1();
	precalculate_type_2();

	scanf("%d", &n);
	for(int i=1; i<=n; ++i) {
		scanf("%d%d%d", &type, &a, &b);
		if (type == 1)
			printf("%d\n", type_1[a][b]);
		if (type == 2)
			printf("%d\n", type_2[a][b]);

	}

	return 0;
}