Cod sursa(job #1573087)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 19 ianuarie 2016 13:12:19
Problema Numerele lui Stirling Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
// Template v2
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<double, double> PKK;
 
const int NMAX = 200;
const int MOD = 98999;
const int INF = int(1e9);
const LL INF64 = LL(1e18);
const LD EPS = 1e-9, PI = 3.1415926535897932384626433832795;

int s[NMAX+5][NMAX+5], S[NMAX+5][NMAX+5],a,n,k,t;

void solve()
{
	s[0][0]=1;
	S[0][0]=1;
	for(int i=1; i<=NMAX; ++i)
	{
		for(int j=1; j<=NMAX; ++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; 
		}
	}
}
 
void read()
{
    cin>>t;
    for(int i=1; i<=t; ++i)
    {
    	cin>>a>>n>>k;
    	if(a==1)
    		cout<<s[n][k];
    	else
			cout<<S[n][k];
		cout<<"\n";
	}
}
 
int main()
{
    cout<<setprecision(16)<<fixed;
    assert(freopen("stirling.in", "rt", stdin));
    assert(freopen("stirling.out", "wt", stdout));
 
    solve();
    read();
    
    return 0;
}