按时间排序,然后类似最长上升子序列那样dp
O(m^2)不要担心TLE
#include <cstdio>
#include <cmath>
#include <cstdlib>
#define MAXM 10003
int n, m;
struct mouse
{
int t, x, y;
} a[MAXM];
int cmp(const void *a, const void *b)
{
return ((struct mouse*)a)->t - ((struct mouse*)b)->t;
}
int max(int a, int b)
{
return a > b ? a : b;
}
int f[MAXM];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i)
scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
qsort(a, m, sizeof(mouse), cmp);
int ans = 0;
for (int i = 0; i < m; ++i)
{
f[i] = 1;
for (int j = 0; j < i; ++j)
if (a[i].t - a[j].t >= labs(a[i].x - a[j].x) + labs(a[i].y - a[j].y))
f[i] = max(f[i], f[j] + 1);
ans = max(ans, f[i]);
}
printf("%d\n", ans);
return 0;
}