AcWing 418. 花生采摘
原题链接
简单
作者:
lyc_6
,
2020-02-26 19:19:05
,
所有人可见
,
阅读 427
//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, k = 1, t, u, ans;
int g[N][N];
struct node
{
int x, y, time, w;
} p[N];
int main()
{
cin >> n >> m >> t;
for(int i = 1; i <= n ; i++)
for(int j = 1; j <= m; j++)
{
cin >> g[i][j];
if(g[i][j] > 0)
{
p[k].x = i;
p[k].y = j;
p[k].w = g[i][j];
k++;
}
}
for(int i = 1; i <= k - 1; i++)
for(int j = i + 1; j <= k; j++)
if(p[i].w < p[j].w) swap(p[i], p[j]);
for(int i = 1; i <= k; i++)
{
u = p[i].x;
if(i == 1) p[i].time = p[i].x + 1;
else p[i].time = p[i - 1].time + abs(p[i].x - p[i - 1].x) + abs(p[i].y - p[i - 1].y) + 1;
if(p[i].time + u <= t) ans += p[i].w;
}
cout << ans << endl;
return 0;
}