下楼问题

来源:互联网 发布:dijkstra算法图解 编辑:程序博客网 时间:2024/05/16 23:34
#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;} 

0 0
原创粉丝点击