Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NMAX 100
- void bktr(int top, int n, int d, int sum, int last, int *cnt) {
- if (sum == d && top == n) {
- ++*cnt;
- return;
- }
- if (sum > d || top > n) {
- return;
- }
- for (int i = last + 1; i <= d; i++) {
- bktr(top + 1, n, d, sum + i, i, cnt);
- }
- }
- int main() {
- int d, n;
- scanf("%d%d", &d, &n);
- int cnt = 0;
- bktr(0, n, d, 0, 0, &cnt);
- printf("%d\n", cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement