leetcode jumping game (backtracking algorithm title)

I was looking at a big brother blog see when a question.
Gangster blog in which it
meaning of the questions:
Here Insert Picture Description
using one of the methods enumerated on backtracking and write down the code to be felt, top-down operation.
The following is a pseudo code oh

//以下都是伪代码
//创建一个判断能不能从起点达到终点
//需要两个参数,一个是用来存储每一个位置能存的步数,而数组下标刚好对应的是第几步,另一个是现在所在的位置
bool jum_can(int a[100],int p){
    //先判断这个位置是不是就是终点,而终点刚好就是数组的长度
    if(p==len(a))  return  true;
    else{
        //就要开始判断了,首先要知道他能走的最大上限,最大上限在 数组对应位置的位置和数组总长度减去当前位置
        int f=min(a[p],len(a)-p);
        //便是开始枚举
        for(int i=0;i<=min;i++){
            jum_can(a,p+i);
        }
        
    }
}

//最后在主函数处
int main()
{
    //创建数组并输入数组数据
    int a[100];
    //(跳过输入部分)
    if(jum_can(a,0))//从0开始
        printf("可以到达");
    else
        printf("不可以到达")return 0;
}
Published 72 original articles · won praise 5 · Views 2832

Guess you like

Origin blog.csdn.net/qq_41115379/article/details/104825534