社区讨论
急
P8816[CSP-J 2022] 上升点列参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo0zy4wh
- 此快照首次捕获于
- 2023/10/22 12:56 2 年前
- 此快照最后确认于
- 2023/11/02 12:27 2 年前
求调,样例二wa
CPP//
#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;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...