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. void precalculate() {
  8. for (int i = 0; i < MAX_SIZE; i++) {
  9. dp[i][0] = 1;
  10. dp[i][i] = 1;
  11. }
  12. for (int i = 2; i < MAX_SIZE; i++) {
  13. for (int j = 1; j < i; j++) {
  14. dp[i][j] = j * dp[i - 1][j] + dp[i - 1][j - 1];
  15. }
  16. }
  17. }
  18.  
  19. int main() {
  20. precalculate();
  21.  
  22. int n;
  23. scanf("%d", &n);
  24.  
  25. for (int i = 0; i < n; i++) {
  26. int a, b;
  27. scanf("%d %d", &a, &b);
  28. printf("%d\n", dp[a][b] % 2);
  29. }
  30. printf("執行時間:%lf秒",(double)clock() / CLOCKS_PER_SEC);
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5464KB
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
0
1
1
1
0
1
0
0
0
1
0
0
0
0
1
-1
0
0
-1
0
0
0
0
-1
1
0
0
0
0
0
0
0
0
執行時間:0.005528秒