BZOJ1207 [HNOI2004] hit Mole

Source: Internet
Author: User

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1207

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

What is this supposed to be called? Violent DP?

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 #defineRep (i,l,r) for (int i=l; i<=r; i++)7 #defineCLR (x, y) memset (x,y,sizeof (×))8 using namespacestd;9 Const intMAXN =10010;TenInlineintRead () { One     intAns =0, F =1; A     Charc =GetChar (); -      for(;!isdigit (c); C =GetChar ()) -     if(c = ='-') F =-1; the      for(; IsDigit (c); C =GetChar ()) -Ans = ans *Ten+ C-'0'; -     returnAns *F; - } + intn,m,ans=-1, T[MAXN],X[MAXN],Y[MAXN],F[MAXN]; -InlineintGetdis (intX1,intY1,intX2,inty2) { +     returnABS (X1-X2) + ABS (y1-y2); A } at intMain () { -n = read (); m =read (); -Rep (I,1, M) { -T[i] = read (); X[i] = read (); Y[i] =read (); -     } -Rep (I,1, m) F[i] =1; inRep (I,1, M) { -Rep (J,1, I-1){ to             if(Getdis (X[i],y[i],x[j],y[j]) <= T[i]-T[j]) +F[i] = max (F[i],f[j] +1); -Ans =Max (ans,f[i]); the         } *     } $printf"%d\n", ans);Panax Notoginseng     return 0; -}
View Code

BZOJ1207 [HNOI2004] hit Mole

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.