NOIP2008 T3 Pass a note to solve the problem report--S.B.S.

Source: Internet
Author: User

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

Input/output format

Input format:

The first line of the input file message.in has 2 integers 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.

Output format:

The output file message.out a common 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.

Input and Output Sample input example # #:
3 30 3 92 8 55 7 0
Sample # # of output:
34
Description

Limit

30% of the data meet: 1<=m,n<=10

100% of the data meet: 1<=m,n<=50

NOIP 2008 Raising the third question of the group

---------------------------I'm a gorgeous split-line------------------------------------------

It's easy to think of an algorithm:Find out 1 a note from ( 1 , 1 ) to ( M,n ) The maximum number of routes . Delete a point value on a pathand find out 1 a note from ( M,n ) to ( 1 , 1 ) The maximum number of routes . statistics two times and The above algorithm is easy to find counter examples, such as. 0 3 9 0 INF 9 2 8 5-------> 2 INF 5 5 7 0 5 INF 0 Section 1 when the optimal value is passed, it causes the first 2 times cannot be delivered. - The greedy algorithm is wrong, so we need to consider the passing of two strips at the same time. - since the path of the Obuchi and the small Xuan is reversible, the starting point is different, but it can be to be viewed simultaneously from (a) Departure Arrival (m,n) Point. - Set F (I 1 , J 1 , I 2 , J 2 ) indicate a note . 1 Arrive (i 1 , J 1 ) location, note 2 Arrive (i 2 , J 2 ) Location of optimal value. Then there, |f[i1-1][j1][i2-1][j2] f (i1,j1,i2,j2) =max|f[i1-1][j1][i2][j2-1] |f[i1][j1-1][i2-1][j2] |f[i1][j1-1][i2][j2-1]- which (i 1 , J 1 ) <> (i 2 , J 2 ) -1<=i 1 , I 2 <=m, 1<=j 1 , J 2 <=n -Complexity of time O (N 2 M 2 ) The code is as follows:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 intd[Wuyi][Wuyi];8 ints[Wuyi][Wuyi][Wuyi][Wuyi];9 intMain ()Ten { One      A     inti,j,k,l; -     intn,m; -Cin>>m>>N; thememset (s),0,sizeof(s)); -memset (D,0,sizeof(d)); -      for(i=1; i<=m;i++) -       for(j=1; j<=n;j++) +Cin>>D[i][j]; -      for(i=1; i<=m;i++) +     { A          for(j=1; j<=n;j++) at         { -              for(k=1; k<=m;k++) -             { -                  for(l=1; l<=n;l++) -                 { -S[i][j][k][l]=max (s[i][j][k][l],s[i-1][j][k-1][l]); inS[i][j][k][l]=max (s[i][j][k][l],s[i-1][j][k][l-1]); -S[i][j][k][l]=max (s[i][j][k][l],s[i][j-1][k-1][l]); toS[i][j][k][l]=max (s[i][j][k][l],s[i][j-1][k][l-1]); +s[i][j][k][l]+=D[i][j]; -                     if(i!=k| | J!=L) s[i][j][k][l]+=D[k][l]; the                 } *             } $         }Panax Notoginseng     } -cout<<S[m][n][m][n]; the     return 0; +}
Pass the note .

NOIP2008 T3 Pass a note to solve the problem report--S.B.S.

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.