题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1207
实在想不到这道题理想复杂度的写法,手残了个O( m^2 )的DP居然也A了。。。
代码:
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXM 10010
int n,m,ans=0;
int x[MAXM],y[MAXM],t[MAXM],f[MAXM];
int main() {
scanf("%d%d",&n,&m);
for (int i=0;i++<m;) {
scanf("%d%d%d",&t[i],&x[i],&y[i]);
f[i]=1;
for (int j=0;j++<i-1;) {
if (abs(x[i]-x[j])+abs(y[i]-y[j])<=t[i]-t[j]) {
f[i]=max(f[i],f[j]+1);
}
}
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}