NOIP 2008 Increase Group T3 Pass Note (DP)

Source: Internet
Author: User

Title Description 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.

Enter a description input Description
The first line of input has 2 integer m and n separated by spaces, indicating that there are m rows n columns (1<=m,n<=50) in the class.
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.

outputs description output Description
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.

sample input to sample
3 3
0 3 9
2 8 5
5 7 0

sample output Sample outputs
34

Data Size & Hint
30% of the data meet: 1<=m,n<=10
100% of the data meet: 1<=m,n<=50

The problem: Because from the top left and right down to follow the right down to the left is no difference, so this question with the box to take the number is exactly the same qaq, the only difference is the matrix of different ╮(╯▽╰)╭. I won't write it again because I have written a check number.
PS: I write the squares to take the number

The code is as follows :

 #include <cstdio> #include <cstring> #include <iostream> using namespace
Std
int map[110][110];
int dp[60][60][60][60];
    int main () {int m,n;
    scanf ("%d%d", &m,&n);
    for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) scanf ("%d", &map[i][j]); for (int i=1;i<=m;i++) for (int j=1;j<=n;j++) for (int. k=1;k<=m;k++) for (int l=1 ; l<=n;l++) {Dp[i][j][k][l]=max (max (Dp[i-1][j][k-1][l],dp[i-1][j][k][l-1]), Max (dp[i
                    ][J-1][K-1][L],DP[I][J-1][K][L-1]);//disgusting four-dimensional DP if (i==k&&j==l) dp[i][j][k][l]+=map[i][j];
                else Dp[i][j][k][l]+=map[i][j]+map[k][l];
    } printf ("%d\n", Dp[m][n][m][n]);
return 0; }

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.