【bzoj1207】[HNOI2004]打鼹鼠
看了数据范围,想想这不暴力可以过??
DP
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define MAXN 10010 int n,m; int ans; int f[MAXN]; int a[MAXN],x[MAXN],y[MAXN]; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { scanf("%d%d%d",&a[i],&x[i],&y[i]); f[i]=1; for (int j=i-1;j>=1;j--) { if (f[j]+1<=f[i]) continue; if (abs(x[i]-x[j])+abs(y[i]-y[j])<=a[i]-a[j]) if (f[i]<f[j]+1) f[i]=f[j]+1; ans=max(ans,f[i]); } } printf("%d",ans=0 ? 1 : ans); return 0; }