tanasaradu

Untitled

Oct 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("stirling.in");
  4. ofstream fout("stirling.out");
  5. const short NMAX=205;
  6. const int MODULO=98999;
  7. int query,dp[NMAX][NMAX],DP[NMAX][NMAX];
  8. int main()
  9. {
  10. int t,n,k;
  11. fin>>query;
  12. ///Recurenta:S(n,k)=-(n-1)*S(n-1,k)+S(n-1,k-1)(De speta I)
  13. ///Recurenta:S(n,k)=S(n-1,k-1)+j*S(i-1,j)(De speta a II-a)
  14. dp[1][1]=DP[1][1]=1;
  15. for(int i=1;i<=NMAX-5;i++)
  16. for(int j=1;j<=NMAX-5;j++)
  17. if(i!=1 || j!=1)
  18. {
  19. dp[i][j]=(dp[i-1][j-1]-(1LL*(i-1)*dp[i-1][j])%MODULO)%MODULO;
  20. DP[i][j]=(DP[i-1][j-1]+(1LL*j*DP[i-1][j])%MODULO)%MODULO;
  21. }
  22. while(query--)
  23. {
  24. fin>>t>>n>>k;
  25. if(t==1)
  26. fout<<dp[n][k]<<"\n";
  27. else fout<<DP[n][k]<<"\n";
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment