线性dp

P2285 [HNOI2004]打鼹鼠

这道题目类似最长上升子序列

这是一道线性dp的题目
怎么设置状态呢?
f[i]:表示最后一只鼹鼠选择i的最大值
转移:f[i] = max(f[i], f[j] + 1)

#include <bits/stdc++.h> 

using namespace std;

const int N = 1e4 + 10;
int f[N];
struct wy
{
	int t, x, y;
}a[N];

bool check(wy t1, wy t2)
{
	if(abs(t1.t - t2.t) >= abs(t1.x - t2.x) + abs(t1.y - t2.y))	return true;
	return false;
}
void solve()
{
	int n, m;	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i) scanf("%d%d%d", &a[i].t, &a[i].x, &a[i].y);
	for(int i = 1; i <= m; ++ i)	f[i] = 1;
	for(int i = 1; i <= m; ++ i)
		for(int j = i - 1; j >= 1; -- j)
			if(check(a[i], a[j]))	
				f[i] = max(f[i], f[j] + 1);
	int ans = 0;
	for(int i = 1; i <= m; ++ i)	ans = max(ans, f[i]);
	printf("%d", ans);
}

int main()
{
//	freopen("1.in", "r", stdin);
//	int t; scanf("%d", &t);
//	while(t --) solve();
	solve();
	return 0;
}
posted @   cxy8  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示