'commit'
This commit is contained in:
42
TangDou/CSP-J/J2-2022/point_dp.cpp
Normal file
42
TangDou/CSP-J/J2-2022/point_dp.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 510;
|
||||
const int M = 110;
|
||||
struct Node {
|
||||
int x, y;
|
||||
bool operator<(const Node &t) const {
|
||||
if (x == t.x) return y < t.y;
|
||||
return x < t.x;
|
||||
}
|
||||
} a[N];
|
||||
|
||||
int f[N][M];
|
||||
int ans;
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
|
||||
sort(a + 1, a + 1 + n);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 0; j <= m; j++)
|
||||
f[i][j] = j + 1;
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j < i; j++) {
|
||||
if (a[i].y < a[j].y) continue;
|
||||
|
||||
int d = a[i].x - a[j].x + a[i].y - a[j].y - 1;
|
||||
|
||||
for (int k = 0; k <= m - d; k++) {
|
||||
f[i][k + d] = max(f[i][k + d], f[j][k] + d + 1);
|
||||
|
||||
ans = max(ans, f[i][k + d] + m - k - d);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user