跳到正文

个人记录

111

kabu约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年1月3日
收录
2026年1月3日
更新
2026年11月13日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
struct node{
    int x,y;
};
//n已有点数量 k可添加点数量
int n,k;
node a[510];
bool cmp(node a, node b) {
    if (a.x == b.x) {
            return a.y < b.y;
    }
    return a.x < b.x;
}
int dp[510][510];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].x >> a[i].y;
    }
    int ans = 0;
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 0; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            dp[i][j] = 1 + i;
            for (int l = 1; l < j; l++) {
                if (a[l].x <= a[j].x && a[l].y <= a[j].y) {
                    int t = a[j].x - a[l].x + a[j].y - a[l].y - 1;
                    if (t <= i) {
                        dp[i][j] = max(dp[i][j], dp[i - t][l] + t + 1);
                    }
                }
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
}
原文