fork(1) download
  1. // 짝수 포함 수열의 개수 (재제출)
  2.  
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. int pick(int n, int* bucket, int m, int toPick, int l, int odd_count);
  8.  
  9. int main(void) {
  10. int N, M, L;
  11. scanf("%d %d %d", &N, &M, &L);
  12. int* bucket = (int*)malloc(sizeof(int) * M);
  13.  
  14. int result = pick(N, bucket, M, M, L, 0);
  15. printf("%d\n", result);
  16.  
  17. free(bucket);
  18. return 0;
  19. }
  20.  
  21. int pick(int n, int* bucket, int m, int toPick, int l, int odd_count) {
  22. int count = 0;
  23.  
  24. if (toPick == 0) {
  25. for (int i = 0; i < m; i++)
  26. printf("%d ", bucket[i]);
  27. printf("\n");
  28. return 1;
  29. }
  30.  
  31. int lastIndex = m - toPick - 1;
  32. int lastPick = (toPick == m ? 1 : bucket[lastIndex] + 1);
  33.  
  34. for (int i = lastPick; i <= n; i++) {
  35. int new_odd = odd_count + (i % 2);
  36. if (new_odd > m - l)
  37. continue;
  38. bucket[lastIndex + 1] = i;
  39. count += pick(n, bucket, m, toPick - 1, l, new_odd);
  40. }
  41.  
  42. return count;
  43. }
Success #stdin #stdout 0.01s 5332KB
stdin
Standard input is empty
stdout
0