Description
Obuchi and Xiao Xuan are good friends and classmates, they always have to talk about endless topics. A quality expansion activities, the class arranged to make a M-row N-column matrix, and Obuchi and small Xuan is arranged at both ends of the matrix diagonal, so they can not directly talk. Fortunately, they can communicate by passing a note. The note to pass through many students to the other hand, Obuchi sitting in the upper left corner of the matrix, coordinates (at a), the small Xuan sits in the bottom right corner of the matrix, coordinates (M,N). From the Obuchi to the small Xuan note can only be passed down or to the right, from the small Xuan to Obuchi note can only be passed up or to the left.
In the activity, Obuchi hope to send a note to the small Xuan, at the same time hope that the small Xuan to reply to him. Every classmate in the class can help them pass, but will only help them once, that is, if the person in the Obuchi hand to the small Xuan Note when help, then in the small Xuan handed to Obuchi when will not help. Vice versa.
There is one more thing to pay attention to, the class each classmate is willing to help a high degree of good and low (note: Obuchi and small Xuan's kindness degree is not defined, input with 0), you can use a 0-100 natural number to express, the greater the number of the more kindness. Obuchi and small Xuan hope as far as possible to find good-hearted students to help pass the note, that is, to find two ways to pass the path, so that the two path to the kindness of the students and the largest. Now, please help Obuchi and Xiao Xuan to find such two paths.
formatInput Format
Enter the first line there are 2 spaces separated by the integer m and N, indicating that the class has M row n column (1<=m,n<=50).
The next M-line is a m*n matrix, and the integer in row J of the matrix indicates the kindness of the student sitting in row J of line I. Each row is separated by a space between n integers.
output Format
Outputs a total line that contains an integer that represents the maximum value of the sum of the kindness of the student who is involved in passing the note back and forth on both paths.
Example 1sample input 1[copy]
3 30 3 92 8 55 7 0
sample Output 1[copy]
34
Limit
Each test point 1s
Tips
Limit
30% of the data meet: 1<=m,n<=10
100% of the data meet: 1<=m,n<=50
Source
The third problem of NOIp2008 raising group
Multi-process DP ratio "three blocks of squares" still less than one dimension
1#include <bits/stdc++.h>2 using namespacestd;3 inta[ -][ -];4 intn,m;5 intf[ $][ -][ -];//F[STEP][X1][X2] indicates that the first step two times the horizontal axis goes to X1 and X2 is the optimal solution6 intMain () {7 8scanf"%d%d",&m,&N);9 for(intI=1; i<=m;i++){Ten for(intj=1; j<=n;j++){ Onescanf"%d",&a[i][j]); A } - } - the for(intstep=1; step<=m+n-3; step++){ - intL,r; - if(step<=m-1) l=1, r=1+Step; - Elsel=step-m+2, r=N; + for(intx1=l;x1<=r;x1++){ - inty11=step+2-X1; + for(intx2=x1+1; x2<=r;x2++){ A inty2=step+2-x2; at - intfrom1=f[step-1][X1][X2];//all from the top - intfrom2=f[step-1][x1-1][X2];//left from left, right from top - intfrom3=f[step-1][x1][x2-1];//left from top, right from left - intfrom4=f[step-1][x1-1][x2-1];//all from left - intDELTA=A[Y11][X1]+A[Y2][X2];//is a[y][x] form, easy to write anti- in if(x2==x1+1){ -F[step][x1][x2]=max (From1,max (FROM2,FROM4)) +Delta; to } + Else if(x2>x1+1){ -F[step][x1][x2]=max (From1,max (From2,max (FROM3,FROM4)) +Delta; the } * } $ }Panax Notoginseng } -cout<<f[n+m-3][n-1][n]; the return 0; +}
Pass the note.