Advertisement
STANAANDREY

bktr 13.6

Apr 17th, 2023
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define NMAX 100
  4.  
  5. void bktr(int top, int n, int d, int sum, int last, int *cnt) {
  6.   if (sum == d && top == n) {
  7.     ++*cnt;
  8.     return;
  9.   }
  10.   if (sum > d || top > n) {
  11.     return;
  12.   }
  13.   for (int i = last + 1; i <= d; i++) {
  14.     bktr(top + 1, n, d, sum + i, i, cnt);
  15.   }
  16. }
  17.  
  18. int main() {
  19.   int d, n;
  20.   scanf("%d%d", &d, &n);
  21.   int cnt = 0;
  22.   bktr(0, n, d, 0, 0, &cnt);
  23.   printf("%d\n", cnt);
  24.  return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement