链接地址:http://bailian.openjudge.cn/practice/1928
题目:
思路:
每次采摘前计算是否能够采摘,模拟题
代码:
#include <iostream>
#include <cstdlib>
using namespace std; int main()
{
int t;
cin>>t;
while(t--)
{
int m,n,k;
cin>>m>>n>>k;
int *arr = new int[m*n];
for(int i = ; i < m; i++)
{
for(int j = ; j < n; j++)
{
cin>>arr[i * n + j];
}
}
int sum = ,ni=,nj;
int max,maxi,maxj;
k -= ;
int flag = ;
do
{
max = -;
for(int i = ; i < m; i++)
{
for(int j = ; j < n; j++)
{
if(max < arr[i * n + j])
{
max = arr[i * n + j];
maxi = i;
maxj = j;
}
}
}
if(flag) {nj = maxj;flag = ;}
int step = abs(maxi - ni) + abs(maxj - nj) + ;
if(step + maxi > k) break;
else
{
k -= step;
sum += max;
ni = maxi;
nj = maxj;
arr[maxi * n + maxj] = ;
} }while();
cout<<sum<<endl;
delete [] arr;
}
return ;
}