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;
}
标签:int,t2,t1,abs,wy,线性,dp
From: https://www.cnblogs.com/cxy8/p/17416518.html