# BZOJ1027 [HNOI2004]打鼹鼠 【dp】

## 1207: [HNOI2004]打鼹鼠

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 3647  Solved: 1746
[Submit][Status][Discuss]

2 2
1 1 1
2 2 2

## Sample Output

1

f[i] = max{f[j] + 1}  【dis(i,j) <= ti - tj】dis指曼哈顿距离

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = head[u]; k != -1; k = edge[k].next)
using namespace std;
const int maxn = 10005,maxm = 100005,INF = 1000000000;
inline int RD(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57) {if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57) {out = (out << 1) + (out << 3) + c - '0'; c = getchar();}
return out * flag;
}
int n,m,f[maxn],ans = 0;
struct node{int t,x,y;}e[maxn];
inline int dis(int u,int v){return abs(e[u].x - e[v].x) + abs(e[u].y - e[v].y);}
int main(){
n = RD(); m = RD();
REP(i,m){
e[i].t = RD(); e[i].x = RD(); e[i].y = RD(); f[i] = 1;
for (int j = 1; j < i; j++)
if (dis(j,i) <= e[i].t - e[j].t && f[j] + 1 > f[i])
f[i] = f[j] + 1;
ans = max(ans,f[i]);
}
cout<<ans;
return 0;
}


posted @ 2017-12-05 13:23  Mychael  阅读(160)  评论(0编辑  收藏  举报