示例运行正确,但是MLT
查看原帖
示例运行正确,但是MLT
1043894
a2963511980楼主2023/12/18 11:08

我的示例运行正确,但是为什么全部MLT QAQ

using namespace std;
int n, a, b;
int k[200];
int ans=9999999;
int index = 1;
void dfs(int x,int step) {
	if (x > n || x <= 0) return;
	if (x == b) {
		if (step < ans) ans = step;
	}

	dfs(x + k[x], step + 1);
	dfs(x - k[x], step + 1);
}


int main() {
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		cin >> k[i];
	}
	dfs(a,0);
	if (ans == 9999999) {
		cout << -1;
		return 0;
	}
	cout << ans;
	
}```
2023/12/18 11:08
加载中...