万紫千红
查看原帖
万紫千红
172075
plmplmplm楼主2024/11/21 13:18

30分https://www.luogu.com.cn/record/190117456

#include<bits/stdc++.h>
using namespace std;

int n, a, b, t[205];
bool r[205];
int rand() {
	int k = 0;
	char ch = getchar();
	while (ch > '9' || ch < '0') {
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		k = k * 10 + ch - '0';
		ch = getchar();
	}
	return k;
}
void dpf(int z, int c) {
	if (r[z])return;
	if (z == b) {
		printf("%d", c);
		a=-1;
		return;
	}
	r[z] = 1;
	if (z + t[z] <= n)dpf(z + t[z], c+1);
	if (z - t[z] >= 0)dpf(z - t[z], c+1);
	r[z] = 0;
	return;
}
int main() {
	n = rand();
	a = rand();
	b = rand();
	for (int i = 1; i <= n; i++) {
		t[i] = rand();
	}
	dpf(a, 0);
	if(a!=-1)printf("-1");
	return 0;
}
2024/11/21 13:18
加载中...