奇妙的递归程序-----台阶问题
2010-05-09 13:24
330 查看
#define STAIR_NUM 5
int total=0;
int index;
int que[STAIR_NUM];
void outputstep()
{
int i;
for(i=0;i<index;i++)
printf("-%d",que[i]);
printf("-/n");
}
void step(int n)
{
if (n==0)
{
total++;
printf("---------the NO.%d ----------/n",total);
outputstep();
return ;
}
que[index++]=1;
step(n-1);
--index;
if (n>1)
{
que[index++]=2;
step(n-2);
--index;
}
if(n>2)
{
que[index++]=3;
step(n-3);
--index;
}
}
main()
{
printf("/n");
printf("--------------------------------------/n");
printf(" stair step /n");
printf("--------------------------------------/n");
step(STAIR_NUM);
printf("/n the total is %d /n",total);
}
int total=0;
int index;
int que[STAIR_NUM];
void outputstep()
{
int i;
for(i=0;i<index;i++)
printf("-%d",que[i]);
printf("-/n");
}
void step(int n)
{
if (n==0)
{
total++;
printf("---------the NO.%d ----------/n",total);
outputstep();
return ;
}
que[index++]=1;
step(n-1);
--index;
if (n>1)
{
que[index++]=2;
step(n-2);
--index;
}
if(n>2)
{
que[index++]=3;
step(n-3);
--index;
}
}
main()
{
printf("/n");
printf("--------------------------------------/n");
printf(" stair step /n");
printf("--------------------------------------/n");
step(STAIR_NUM);
printf("/n the total is %d /n",total);
}
相关文章推荐
- C#趣味程序---爱因斯坦的台阶问题
- 递归问题,实例4,第39级台阶
- 小程序:备考问题&递归实现每天备考时间的分配(含代码)
- 洛谷 1057——台阶问题(递推与递归二分)
- 青蛙跳台阶问题的递归思路
- 跳台阶问题|斐波那契递归的复杂度问题|整数划分问题
- 程序算法艺术与实践:递归策略之矩阵乘法问题
- 递归大总结之台阶问题
- 跳台阶问题|斐波那契|递归
- 【重走普及路】【递归】台阶问题
- 上台阶问题(递归)
- 递归的logN的优化(菲波那契数列,青蛙上台阶问题,母牛问题)!!!!
- 递归程序求解问题的通用法则
- 问题一、走台阶问题(递归和动态规划)
- 递归大总结之n台阶问题
- 递归-微软面试100题-台阶问题
- 27.跳台阶问题(递归)
- 递归程序与全排列问题
- 递归函数的练习,汉诺塔问题的程序实现(递归)
- 跳台阶问题(递归)