急
查看原帖
急
236660
V_Me_50楼主2023/10/20 20:27

求调,样例二wa

//
#define debug
#include <bits/stdc++.h>
#define IM INT_MAX
#define IMN INT_MIN
#define LM LLONG_MAX
#define LMN LLONG_MIN
#define ll long long

using namespace std;

const int Maxm = 1e2 + 1, Maxn = 5e2 + 1;
int dp[Maxn][Maxm], n, k, ans = IMN;
struct node{
	int x, y;
}a[Maxn];

inline int read(){
	int fs = 1, x = 0;
	char ch = getchar();
	while(ch < '0' || ch > '9'){
		if(ch == '-'){
			fs = -1;
		}
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x * fs;
}

bool cmp(const node &a, const node &b){
	return (a.x == b.x ? a.y < b.y : a.x < b.x); 
}

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  n = read(), k = read();
  for(int i = 1; i <= n; i++){
  	a[i].x = read();
  	a[i].y = read();
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		dp[i][k] = 1;
		for(int j = 1; j <= k; j++){
			for(int l = 1; l < i; l++){
				if(a[l].x > a[i].x || a[l].x > a[i].x){
					continue;
				}
				int x = abs(a[i].x - a[l].x), y = abs(a[i].y - a[l].y);
				if(x + y - 1 <= k){
					dp[i][j] = max(dp[i][j], dp[l][j + x + y - 1] + x + y);
				}
			}
		}
	}
	int ans = IMN;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= k; j++){
			ans = max(ans, dp[i][j] + j);
		} 
	}
	cout << ans;
	return 0;
}

2023/10/20 20:27
加载中...