诡异事件
查看原帖
诡异事件
1389448
dedxxa楼主2024/10/1 15:18
#include<bits/stdc++.h>
using namespace std;
int m[205],n,a,b;
int dfs(int x,int step){
	if(x==b){
//		cout<<step;
		return step;
	}
	if(x+m[x]<=n) dfs(x+m[x],step+1);
	if(x-m[x]>=1) dfs(x-m[x],step+1);
	
}
int main() {
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) cin>>m[i];
	cout<<dfs(a,0);
	return 0;
}

在函数内是对的,输出出来不知道为啥总是-2

2024/10/1 15:18
加载中...