Cod sursa(job #2758876)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 13 iunie 2021 20:52:43
Problema Numerele lui Stirling Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <cstdio>

using namespace std;

#define MOD 98999
int S1[205][205]; // S1[n][k] = permutation of length n with k cycles
int S2[205][205]; // S2[n][k] = put n balls in k boxes
int N = 204;  

void StirlingI()
{
  S1[0][0] = 1;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= i; ++j)
      S1[i][j] = (S1[i-1][j-1] - (i - 1) * S1[i-1][j]) % MOD;
}

void StirlingII()
{
  S2[0][0] = 1;
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= i; ++j)
      S2[i][j] = (S2[i-1][j-1] + j * S2[i-1][j]) % MOD;  
}

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

  StirlingI();
  StirlingII();

  int T;
  scanf("%d", &T);
  int op, n, k;
  while (T--) {
    scanf("%d%d%d", &op, &n, &k);
    if (op == 1)
      printf("%d\n", S1[n][k]);
    else
      printf("%d\n", S2[n][k]);
  }
  
  return 0;
}