110,538
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
// 上台阶.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
//声明树节点
typedef struct _Node
{
long int data;
struct _Node *left;
struct _Node *right;
} Node,*pNode;
int num=0;
int STEP=30;
int Next(pNode );
int _tmain(int argc, _TCHAR* argv[])
{
pNode node=(pNode)malloc(sizeof(Node));
node->data=0;
Next(node);
printf("\n\n\n总共有%d走法",num);
getchar();
return 0;
}
int Next(pNode pN)
{
int left=pN->data+1;
int right=pN->data+2;
if(left==STEP)
num++;
else if(left<STEP)
{
pNode lnew=(pNode)malloc(sizeof(Node));
pN->left=lnew;
lnew->data=pN->data+1;
Next(lnew);
}
if(right==STEP)
num++;
else if(right<STEP)
{
pNode lnew=(pNode)malloc(sizeof(Node));
pN->left=lnew;
lnew->data=pN->data+1;
Next(lnew);
}
return 0;
}