2004 Peanut Picking

Source: Internet
Author: User

Title Description Description

Mr. Robinson has a pet monkey named Toto. This day, they are walking along the country road, suddenly found on the roadside signs with a small note: "Welcome to free tasting my peanut!" --Bear word ".

Mr. Robinson and Toto are very happy, because peanuts are their favorite. Behind the sign, there really is a peanut field on the roadside, and the peanut plants are neatly arranged in a rectangular grid (1). With a lot of experience, you can see how many peanuts are in each peanut plant. In order to train a lot of arithmetic, Mr. Robinson said: "You first find the most peanuts plant, to pick its peanuts, and then find the remaining plants in the most peanuts, to pick its peanuts; and so on, but you must be in my limited time to return to the roadside. ”

We assume that a lot can do one of the following four things in each unit time:

1) jump from the roadside to a peanut plant closest to the roadside (i.e. the first row);

2) jump from one plant to another plant adjacent to or around it;

3) Picking peanuts under a plant;

4) Jump back to the roadside from a peanut plant closest to the roadside (i.e. the first row).

Now given the size of a peanut field and the distribution of peanuts, in the limited time, how many can the maximum number of peanuts to be harvested? Note that it is possible that only some of the plants have peanuts under them, assuming that the number of peanuts under these plants varies.

For example, in the Peanut field shown in Figure 2, there are peanuts in the plants (2, 5), (3, 7), (4, 2), (5, 4), respectively, 13, 7, 15, 9. Along the route of the diagram, a maximum of 37 peanuts can be harvested in 21 unit time.

Enter a description Input Description

The input first line consists of three integers, M, N and K, separated by a space, which indicates that the peanut field size is M * N (1 <= m, n <= 20), the limit time for a lot of peanuts is K (0 <= k <= 1000) unit time. The next M-line, each line includes n non-negative integers, and is separated by a space; the J-Integer pij (0 <= pij <= 500) of line I + 1 indicates the number of peanuts under the Peanut field plant (i, j), and 0 indicates that there are no peanuts under the plant.

Output description Output Description

The output includes one row, which contains only an integer, that is, the maximum number of peanuts that can be harvested within a limited time.

Sample input Sample Input

"Sample Input 1"

6 7 21

0 0 0 0 0 0 0

0 0 0 0 13 0 0

0 0 0 0 0 0 7

0 15 0 0 0 0 0

0 0 0 9 0 0 0

0 0 0 0 0 0 0

"Sample Input 2"

6 7 20

0 0 0 0 0 0 0

0 0 0 0 13 0 0

0 0 0 0 0 0 7

0 15 0 0 0 0 0

0 0 0 9 0 0 0

0 0 0 0 0 0 0

Sample output Sample Output

"Sample Output 1"

37

"Sample Output 2"

28

Data range and Tips Data Size & Hint

Exercises

Simulation.

Every time to pick the most places of peanuts, and to determine the end of the peanut can go back, can take off, you can not give up and go back.

var a:array[1..100,1..100]of longint;

M,n,k,i,j,l,x,y,z,b,c,t,s,max:longint;

Begin

READLN (N,M,K);

For I:=1 to N do

For J:=1 to M do read (A[i,j]);

For I:=1 to N do

For J:=1 to M do

If A[i,j]<>0 then Inc (T);

For I:=1 to T-do

Begin

Max:=-maxlongint;

For J:=1 to N do

For L:=1 to M do

If A[j,l]>max Then

Begin

MAX:=A[J,L];

X:=j;

Y:=l;

End

If I=1 then c:=y;

Z:=z+abs (x-b) +abs (y-c) +1;

if (z+x) <=k Then

Begin

S:=s+max;

a[x,y]:=0;

B:=x;

C:=y;

End

else break;

End

Write (s);

End.

2004 Peanut Picking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.