-
Notifications
You must be signed in to change notification settings - Fork 0
/
洛谷P1135 奇怪的电梯.cpp
41 lines (40 loc) · 953 Bytes
/
洛谷P1135 奇怪的电梯.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//P1135 奇怪的电梯
//https://www.luogu.com.cn/problem/P1135
//https://www.luogu.com.cn/record/76276857 40
//https://www.luogu.com.cn/record/76277091 70
//https://www.luogu.com.cn/record/76277091 80
//https://www.luogu.com.cn/record/76277279 90
//https://www.luogu.com.cn/record/76277318 删掉了一个没多大用还费时间的“全标记”检测
#define MINT 2147483647
#include<iostream>
using namespace std;
int n,a,b,nn[201],ans=MINT;
bool fs[201];
void dt(int aa,int bb){
if(bb>ans) return;
if(aa==b){
if(bb<ans){
ans=bb;
}
return;
}
if(aa>=1&&aa<=n){
if(fs[aa]!=1){
fs[aa]=1;
dt(aa+nn[aa],bb+1);
dt(aa-nn[aa],bb+1);
fs[aa]=0;
}
}
return;
}
int main(){
cin>>n>>a>>b;
for(int i=1;i<=n;i++){
cin>>nn[i];
}
dt(a,0);
if(ans!=MINT) cout<<ans<<endl;
else cout<<"-1"<<endl;
return 0;
}