打鼹鼠

题目链接:https://www.luogu.com.cn/problem/P2285

题意:

思路:

记dp[i]为以i为开头时能打的鼹鼠数目
从后向前枚举

转移条件是后面-前面的时间大于等于二者曼哈顿距离

初始化都为1

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define endl "\n"
#define fi first
#define se second
//#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll llmax=LLONG_MAX;
const int maxn=1e5+5;
const int mod=1e9+7;
struct node{
	int t;int x,y;
};
int cal(int a,int b,int c,int d){
	return abs(a-c)+abs(b-d);
}
void solve(){
	int n,m;cin>>n>>m;
	vector<node>a(m+1);
	rep(i,1,m){
		cin>>a[i].t>>a[i].x>>a[i].y;
	}
	vector<int>dp(m+1,1);
	dp[0]=0;
	int r=-inf;
	for(int i=m;i>=1;i--){
		for(int j=i+1;j<=m;j++){
		if(cal(a[i].x,a[i].y,a[j].x,a[j].y)<=a[j].t-a[i].t){
			dp[i]=max(dp[i],dp[j]+1);
		}	
	}
		r=max(dp[i],r);
	}
	cout<<r<<endl;
}

signed main()
{
	ios::sync_with_stdio(false),cin.tie(0);
	int T=1;
	
	while(T--){
	solve();
	}
	
	return 0;
}


posted @ 2025-03-06 17:10  Marinaco  阅读(17)  评论(0)    收藏  举报
//雪花飘落效果