• 个人简介

    #include <bits/stdc++.h>
    using namespace std;
    int n,a,b;
    int p[211];
    int flag=0;
    int v[211];
    queue<int> q;
    void bfs(){
    	for(int i=1; i<=n; i++) v[i]=-1;
    	v[a]=0;
    	q.push(a);
    	while(!q.empty()){
    		int now=q.front();
    		q.pop();
    		int x1=now+p[now];
    		int x2=now-p[now];
    		if(x1<=n&&v[x1]==-1){
    			v[x1]=v[now]+1;
    			q.push(x1);
    		}if(x2>=1&&v[x2]==-1){
    			v[x2]=v[now]+1;
    			q.push(x2);
    		}
    	}
    }
    int main(){
    	cin>>n>>a>>b;
    	for(int i=1; i<=n; i++){
    		cin>>p[i];
    	}bfs();
    	cout<<v[b];
    }
    
    
  • 通过的题目

  • 最近编写的题解

    This person is lazy and didn't write any solutions.
  • 竞赛成绩

    最近没有参加过比赛!

题目标签

动态规划 DP
8
搜索
3
递推
3
NOIP 提高组
3
模拟
2
NOIP 普及组
2
记忆化搜索
2
贪心
2
1996
1
2001
1
2007
1
2008
1
2013
1
剪枝
1
数学
1
NOI 导刊
1
组合数学
1
深度优先搜索 DFS
1
拓扑排序
1
算法
1