fork download
  1. #include <stdio.h>
  2.  
  3. #define MAX_N 1001
  4. #define MAX_M 101
  5.  
  6. int memo[MAX_N][MAX_M];
  7.  
  8. int S(int n, int m) {
  9. if (memo[n][m] != -1)
  10. return memo[n][m];
  11.  
  12. if (n > m && m > 1)
  13. return memo[n][m] = m * S(n - 1, m) + S(n - 1, m - 1);
  14. else
  15. return memo[n][m] = 1;
  16. }
  17.  
  18. int main(void) {
  19. int cases = 0;
  20.  
  21. scanf("%d", &cases);
  22.  
  23. while (cases--) {
  24. int n = 0, m = 0;
  25.  
  26. scanf("%d %d", &n, &m);
  27.  
  28. // Initialize memoization table
  29. for (int i = 0; i <= n; ++i) {
  30. for (int j = 0; j <= m; ++j) {
  31. memo[i][j] = -1;
  32. }
  33. }
  34.  
  35. printf("%d\n", S(n, m) & 1);
  36. }
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 5304KB
stdin
2
4 2
10 5
stdout
1
1