以前:这题是人做的吗?
现在:大水题
.......................................................................
思路:大概就是用一个结构体排序,然后模拟
CODE
#include<bits/stdc++.h>
using namespace std;
struct node{
int val, y, x;
}a[500];
int m, n, k;
bool cmp(node x1, node x2){
return x1.val > x2.val;
}
signed main(){
cin >> m >> n >> k;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
int x;
cin >> x;
node no;
no.val = x, no.y = i, no.x = j;
a[(i - 1) * n + j] = no;
}
}
int x = 0, y = 0, ans = 0;
sort(a + 1, a + m * n + 1, cmp);
for(int i = 1; i <= m * n; i++){
int cost;
if(x == 0 && y == 0){
cost = a[i].y;
if(cost + a[i].y + 1 <= k){
k -= cost + 1;
ans += a[i].val;
x = a[i].x;
y = a[i].y;
}
else break;
}
else{
cost = abs(a[i].x - x) + abs(a[i].y - y);
if(cost + a[i].y + 1 <= k){
k -= cost + 1;
ans += a[i].val;
x = a[i].x;
y = a[i].y;
}
else break;
}
}
cout << ans;
return 0;
}