caioj 1413 动态规划4:打鼹鼠

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34416123/article/details/82117485

记住一定要区分n和m分别代表什么,我已经因为这个两道题浪费很多时间了
然后这个道题有点类似最长上升子序列n平方的做法,只是判断的条件不同而已

#include<cstdio>
#include<algorithm>
#include<cmath>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

const int MAXN = 11234;
int f[MAXN], n, m; 
struct node
{
	int t, x, y;
	void read() { scanf("%d%d%d", &t, &x, &y); }
	bool operator < (const node& rhs) const
	{
		return t < rhs.t; 
	}
}a[MAXN];

bool judge(int i, int j)
{
	return (a[j].t - a[i].t) >= abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
}

int main()
{
	scanf("%d%d", &n, &m);
	REP(i, 0, m) a[i].read();
	sort(a, a + m);
	
	int ans = 1;
	f[0] = 1;
	REP(i, 1, m)
	{
		f[i] = 1;
		REP(j, 0, i)
			if(judge(j, i))
				f[i] = max(f[i], f[j] + 1);
		ans = max(ans, f[i]);
	}
	printf("%d\n", ans);

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_34416123/article/details/82117485
今日推荐