O (N2) DP has a better solution I won't
#include <cstdio> #include <cstring> #include <cctype> #include <algorithm>using namespace std; #define REP (I,s,t) for (int. i=s;i<=t;i++) #define DWN (i,s,t) for (int i=s;i>=t;i--) #define CLR (x,c) memset (X,c, sizeof (x)) int read () { int x=0,f=1;char c=getchar (); while (!isdigit (c)) { if (c== '-') F=-1;c=getchar (); } while (IsDigit (c)) x=x*10+c-' 0 ', C=getchar (); return x*f;} const int nmax=1e4+5;struct edge{ int u,v,t;}; Edge Es[nmax];int f[nmax];void maxs (int &a,int b) { if (a<b) a=b;} int main () { int n=read (), M=read (), ans=0; Rep (i,1,m) Es[i].t=read (), Es[i].u=read (), Es[i].v=read (); Rep (i,1,m) { int tmp=1; Dwn (j,i-1,1) if (ABS (ES[I].U-ES[J].U) +abs (ES[I].V-ES[J].V) <=es[i].t-es[j].t) maxs (tmp,f[j]+1); F[I]=TMP;MAXS (ans,tmp); } printf ("%d\n", ans); return 0;}
1207: [HNOI2004] hit mole time limit:10 Sec Memory limit:162 MB
submit:2623 solved:1289
[Submit] [Status] [Discuss] 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
The first behavior n (n<=1000), M (m<=10000), where m represents the number of moles appearing in this period of time, and the next m row has three data per row time,x,y indicates that there is a mole at the beginning of the game time, A mole appeared in the grid of the first X row. 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
Contains only a positive integer representing the maximum number of moles killed
Sample Input2 2
1 1 1
2 2 2
Sample Output1HINT Source [Submit] [Status] [Discuss]
bzoj1207: [HNOI2004] Hit Mole