1668: [Usaco2006 Oct]cow Pie Treasures Pie of Fortune time Limit:3 Sec Memory limit:64 MB
submit:498 solved:289
[Submit] [Status] Description
Recently, cows have been keen to wrap coins in flour and bake them into pies. Block I pies contain Ni (1<=ni<=25) nugget coins, and this number is prominently marked on the surface of the pie. The cows lined up all the baked pies on the grass as a matrix of R row (1<=r<=100) column C (1<=c<=100). You are now standing at the edge of the pie with the coordinates, of course, you can get all the gold coins in that pie. You must go from the present position to the other side of the meadow and stop walking next to the pie (r,c). Every time you move, you have to go to the next column of a pie, and the number of rows cannot be changed by more than 1 (that is, if you are now standing at the edge of the pie with coordinates (R,C), next you can go to the coordinates (R-1,C+1), (r,c+1), or (r+1,c+1) the pie next). When you pass by the side of a pie, you can take away all the gold coins in the pie. Of course, you won't be willing to lose your handy gold coins by leaving the lawn halfway, but eventually you'll have to stop at the r,c pie. Now, you get a table labeled with the number of coins in each pie in the pie matrix. So, according to the rules, how many coins can you get? For example, the cows lined up the pie as a matrix in which the numbers in the matrix represent the number of coins in the pie in that position:
6 5 3 7 9 2 7
2 4 3 5 6 8 6
4 9 9 9 1 5 8
Here's the legal route.
follow the above route to walk, altogether can obtain 6+4+9+9+6+5+8=47 a gold coin. As a rule, you can get up to 50 gold coins in this matrix, as shown in the following route:
Input
* Line 1th: Two integers separated by a space, R and C
* 2nd. R+1 rows: Each row contains a positive integer separated by spaces, representing the number of coins in a row from left to right in each pie
Output
* Line 1th: Output a positive integer indicating the maximum number of coins you can collect
Sample INPUT3 7
6 5 3 7 9 2 7
2 4 3 5 6 8 6
4 9 9 9 1 5 8
Sample Output50
HINT Source
Gold
Puzzle: Pit pit, this huge water can WA once ... Originally I did not consider some of the points at all, and at this point DP when a few home are zero, if ignoring the cold, this could not pass the point instead of a value, so that the wrong back (note ah, hansbug classmate you always so tease than really good tut)
1 var2 I,j,k,l,m,n:longint;3B:Array[0.. $,0.. $] ofLongint;4 functionMax (x,y:longint): Longint;5 begin6 ifX>y ThenMax:=xElsemax:=y;7 End;8 begin9 readln (n,m);Ten fori:=1 toN Do One begin A forj:=1 toM Do - read (a[i,j]); - Readln; the End; -Fillchar (b,sizeof (b),0); -b[1,1]:=a[1,1]; - fori:=2 toM Do + begin - forj:=1 toN Do + begin AB[j,i]:=max (b[j-1, I-1],max (b[j,i-1],b[j+1, I-1]))+A[j,i]; at ifB[j,i]=a[j,i] Thenb[j,i]:=0; - End; - End; - Writeln (b[n,m]); - End.
1668: [Usaco2006 Oct]cow Pie Treasures the riches in pie