下楼问题

#include <stdio.h>

int take[99];
int num = 0;

void _try(int i, int s) {
    int j, k;

    for (j = 3; j > 0; j--) {
        if (i >= j) {
            take[s] = j;
            if (i == j) {
                num++;
                printf("scheme %d: ", num);
                for (k = 1; k <= s; k++)
                    printf("%d ", take[k]);
                putchar('\n');
            } else {
                _try(i - j, s + 1);
            }
        }
    }
}

int main() {
    int h;

    puts("Please input the number of steps in the stairs.");
    scanf("%d", &h);
    _try(h, 1);
    printf("The total number of scheme: %d\n", num);
    return 0;
}
 

你可能感兴趣的:(下楼问题)