Description
The mole is a kind of animal that likes digging a hole very much, but every time, it still likes to poke his head out to the ground to breathe.
According to this feature, Ah Q wrote a game of hitting the mole: in a n*n grid, at some point the mole would try to breathe through a grid. You can control a robot to hit a mole, and if I moment the mole appears in a grid and the robot is in the same grid, the mole will be killed by the robot. And the robot can only move one cell at a time or stay where it is. The movement of a robot is to move from the current grid to the adjacent mesh, that is, from the coordinates (I,J) of the grid (I-1, J), (I+1, J), (I,j-1), (i,j+1) Four meshes, the robot cannot walk out of the entire n*n grid. At the beginning of the game, you are free to select the initial position of the robot.
Now you know the time and place where the mole appeared during a period of time, hoping you would write a program that would allow the robot to kill as many moles in this period of time.
Input
You will read the data from the file mole.in, the first act of the file N (n<=1000), M (m<=10000), where m represents the number of moles that appear in this period of time, and the next m row has three data time,x per row, Y means that there is a mole at the beginning of the game time, a mole in the first x row of the grid. Time is given in ascending order. Note that there may be many moles at the same time, but only one mole may appear at the same time in the same place.
Output
The output file, Mole.out, contains only a positive integer that represents the maximum number of moles killed.
Sample Input
2 2
1 1 1
2 2 2
Sample Output
1
Exercises
Water DP AH.
Code
var n,m,max:longint;
T,a,b,f:array [0..10001] of Longint;
Procedure Init;
var i:longint;
Begin READLN (N,M);
For I:=1 to M do Readln (T[i],a[i],b[i]);
End
Procedure main;
var i,j:longint;
Begin for I:=1 to M do f[i]:=1; For i:=2-to-M do-j:=1 to I-1 does if ABS (A[i]-a[j]) +abs (B[i]-b[j]) <=abs (T[i]-t[j]) then if F[J]+1&G
T;f[i] then f[i]:=f[j]+1;
End
procedure Print;
var i:longint;
Begin for I:=1 to M does if F[i]>max then max:=f[i];
Write (max);
End
Begin init;
Main
Print
End.