当前位置:网站首页>-Pickling peanuts-

-Pickling peanuts-

2022-08-10 01:48:00 -JMY-

Title description

When participating in the "Peanut Picking" competition, the examiner will present a peanut field with n rows and m columns, on which a total of n*m peanut seedlings are planted.Each peanut plant bears a certain number of peanut fruits. At the beginning of the competition, the contestants stand in the 1st row and the 1st column. Now it is required to find the peanut plant with the most peanut fruits in the shortest time (data guarantee peanutsThere is only one plant with the most fruit), and then go south (down) and then east (right) to pick its peanuts, and pick the peanuts under other peanut plants that pass along the way.Come down, but not allowed to pick peanut plants that have not passed by, otherwise it will be dealt with as a foul.How many peanuts can this player pick in total?
Such as a peanut field with n=5, m=6
1st column 2nd column 3rd column 4th column 5th column 6th column
1st row 5 5 4 7 5 13
Line 2 9 6 3 2 8 7> Line 3 10 14 0 1 9 4
Line 4 6 9 18 25 0
Ring 5 3 1 2 9 0 2
Yes, yes you canIf the peanut plant with the most peanuts is found at (4, 5), the order of picking should be (1, 1)-(2, 1)-(3, 1)-(4, 1)-(4, 2)-(4,3)-(4,4)-(4,5), the total number of peanuts picked is 5+9+10+4+6+9+18+25=86.

Enter

The first row has two integers n and m ( 1 < n,m <= 100 ), which means that the peanut field has n rows and m columns.
Lines 2 to n+1, each line has m integers separated by spaces, the jth integer Pij (0 <= Pij <= 700) in line i + 1 represents the plants in the peanut field (i, j) The number of peanuts under the plant, 0 means there is no peanut under the plant.

Output

There is only one line, an integer, indicating the total number of peanuts picked by the contestants.

Sample input

5 65 7 4 5 1 139 6 3 2 8 710 14 0 1 9 44 6 9 18 25 03 1 2 9 0 2

Sample output

86

Reference code:

#include
using namespace std;
int n,m,a[105][105],x,y,s,maxn;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i for(int j=0;j scanf("%d",&a[i][j]);
for(int i=0;i for(int j=0;j if(a[i][j]>maxn){
maxn=a[i][j];
x=j+1;
y=i+1;
}
for(int i=0;i s+=a[i][0];
for(int i=1;i s+=a[y-1][i];
printf("%d",s);
return 0;
}

原网站

版权声明
本文为[-JMY-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208092346036813.html