fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #define MAX_SIZE 1000 // 可調整為適當大小
  4.  
  5. int dp[MAX_SIZE][MAX_SIZE];
  6.  
  7. int S(int n, int m) {
  8. if (n <= 0 || m <= 0 || m > n) return 0;
  9. if (m == 1 || m == n) return 1;
  10.  
  11. if (dp[n][m] != 0) return dp[n][m]; // 如果已經計算過,直接返回結果
  12.  
  13. return dp[n][m] = m * S(n - 1, m) + S(n - 1, m - 1);
  14. }
  15.  
  16. int main() {
  17. int n;
  18. scanf("%d", &n);
  19.  
  20. for (int i = 0; i < n; i++) {
  21. int a, b;
  22. scanf("%d %d", &a, &b);
  23. printf("%d\n", S(a, b) % 2);
  24. }
  25. printf("執行時間:%lf秒",(double)clock() / CLOCKS_PER_SEC);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.02s 5484KB
stdin
35
4 2
2 2
3 2
3 3
4 3
4 4
5 2
5 4
6 3
7 5
10 9
12 2
23 22
25 12
30 13
42 9
43 41
49 36
98 28
99 12
129 33
239 86
259 143
427 261
449 387
453 404
470 46
238 90
539 109
673 273
729 721
849 238
999 298
998 587
893 389
stdout
1
1
1
1
0
1
1
0
0
0
1
1
1
0
1
1
1
0
0
0
1
0
0
0
1
0
1
0
0
0
0
0
0
0
0
執行時間:0.014958秒