这个题我只枚举前 1000 个点进行转移,结果 WA on #6。改成枚举 2000 个点就 AC 了。但我怎么想都觉得只要枚举 1000 个,题解也都是枚举的 1000 个。
求解答/kk
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int r, n;
int t[maxn], x[maxn], y[maxn];
int dp[maxn];
int ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> r >> n;
for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
t[0] = 0, x[0] = y[0] = 1;
for (int i = 1; i <= n; i++) {
if (x[i] - 1 + y[i] - 1 <= t[i]) dp[i] = 1;
else dp[i] = -1e9;
for (int j = max(i - 1000, 0); j < i; j++)
if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= t[i] - t[j]) dp[i] = max(dp[i], dp[j] + 1);
ans = max(ans, dp[i]);
}
cout << ans << '\n';
return 0;
}