fork 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. if(m - odd_count < l) return 0;
  23. if(toPick == 0) return 1;
  24. int lastIndex = m - toPick - 1;
  25. int lastPick = (toPick == m) ? 1 : bucket[lastIndex] + 1;
  26. int count = 0;
  27. for (int i = lastPick; i <= n; i++) {
  28. bucket[lastIndex + 1] = i;
  29. count += pick(n, bucket, m, toPick - 1, l, odd_count + i% 2);
  30. }
  31. return count;
  32. }
Success #stdin #stdout 0s 5320KB
stdin
6 3 2
stdout
10