Files
Data-Structure/Algorithm/DP-DynamicProgramming/Linear-DP/P2285 [HNOI2004] 打鼹鼠.cpp
2025-09-21 12:21:50 +08:00

37 lines
907 B
C++

#include <iostream>
#include <tuple>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
//tuple(t, x, y)
int dist(const tuple<int, int, int>& i, const tuple<int, int, int>& j){
return ( abs(get<1>(i) - get<1>(j)) + abs(get<2>(i) - get<2>(j)) );
}
int time(const tuple<int, int, int>& i, const tuple<int, int, int>& j){
return abs( get<0>(i) - get<0>(j) );
}
int main(){
int n, m;
cin >> n >> m;
//n * n, m 个鼹鼠
vector<tuple<int, int, int>> ham(m);
vector<int> dp(m, 1);
for(int i = 0; i < m; i++){
int t, x, y;
cin >> t >> x >> y;
ham[i] = make_tuple(t, x, y);
}
//dp[m] = max (能走到的(t2 - t1 > dist)dp[x] + 1)
for(int i = 1; i < m; i++){
for(int j = 0; j < i; j++){
//如果能走到就更新
if(dist(ham[i], ham[j]) <= time(ham[i], ham[j])){
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
return 0;
}