Pagini recente » Cod sursa (job #2940325) | Cod sursa (job #434377) | Cod sursa (job #1062352) | Cod sursa (job #506954) | Cod sursa (job #559684)
Cod sursa(job #559684)
#include<cstdio>
#define infile "stirling.in"
#define outfile "stirling.out"
#define mod 98999
#define n_max 205
typedef int matrice [n_max][n_max];
using namespace std;
void citeste();
void stirling1(int,int);
void stirling2(int,int);
matrice s,S;
void citeste()
{
freopen(infile,"r",stdin);
freopen(outfile,"w",stdout);
int speta,t,n,m;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d",&speta);
scanf("%d%d",&n,&m);
switch(speta)
{
case 1: stirling1(n,m), printf("%d\n",s[n][m]); break;
case 2: stirling2(n,m), printf("%d\n",S[n][m]); break;
}
}
fclose(stdin);
fclose(stdout);
}
void stirling1(int n, int m)
{
if(n<m) s[n][m]=0;
if(s[n][m]==-1)
{
if(s[n-1][m-1]==-1) stirling1(n-1,m-1);
if(s[n-1][m]==-1) stirling1(n-1,m);
s[n][m] = s[n-1][m-1] - (1LL*(n-1) * s[n-1][m])%mod;
}
}
void stirling2(int n, int m)
{
if(m==1 || n==m) S[n][m]=1;
if(S[n][m]==-1)
{
if(S[n-1][m-1]==-1) stirling2(n-1,m-1);
if(S[n-1][m]!=-1) stirling2(n-1,m);
S[n][m] = S[n-1][m-1] + (1LL * m * S[n-1][m])%mod;
}
}
int main()
{
for(int i=0;i<n_max;i++)
for(int j=0;j<n_max;j++)
s[i][j]=S[i][j]=-1;
s[1][1]=S[1][1]=1;
citeste();
return 0;
}