class Solution {
public:
bool canCross(vector<int>& stones) {
int n = stones.size();
vector<vector<bool>> f = vector<vector<bool>>(n, vector<bool>(n, false));
f[0][0] = true;
for (int i = 1; i < n; ++i) {
for (int j = 0; j < i; ++j) {
int k = stones[i] - stones[j];
if (k <= j + 1) {
f[i][k] = f[j][k - 1] || f[j][k] || f[j][k + 1];
if (i == n - 1 && f[i][k]) {
return true;
}
}
}
}
return false;
}
};