Describe
Obuchi and Xiao Xuan are good friends and classmates, they always have to talk about endless topic. A quality expansion activities, the class arranged to make a M row n columns of the matrix, and Obuchi and small porch is arranged at both ends of the matrix diagonal, so they can not directly talk. Luckily, they can communicate by passing notes. Note to pass through many students to the other hand, Obuchi sitting in the upper left corner of the matrix, coordinates (1,1), small Xuan sits in the lower 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 a small porch to Obuchi note can only be passed up or left.
In the activity, Obuchi hope to small Xuan pass a note, and hope small porch to his reply. Every student in the class can help them pass, but only will help them once, that is, if the person in Obuchi hand to small Xuan Note when help, then in small Xuan handed to Obuchi time will not help again. Vice versa.
There is another thing to pay attention to the class, each student is willing to help the degree of goodwill has a high and low (note: Obuchi and small porch of the kind of no definition, input with 0), you can use a 0-100 natural number to say, the greater the number of good intentions. Obuchi and small Xuan hope that as far as possible to find a high degree of kindness students to help pass the note, that is to find two pass path, make these two paths on the level of kindness of students only and the largest. Now, please help Obuchi and Xiao Xuan find such two paths. Format input Format
Enter the first line with 2 integers m and n separated by a space, indicating that there are m rows n columns (1<=m,n<=50) in the class.
The next M row is a m*n matrix in which the whole number of the J-column in The matrix indicates the kindness of the students sitting in the J column of line I. The n integers of each row are separated by a space. Output format
The output is a row that contains an integer that represents the maximum value of the sum of the kindness of the students who are involved in passing the note on both paths. Sample Example Input
3 3
0 3 9 2 8 5 5 7 0
Sample output
34
Limit
1s tips for each test point
Limit
30% Data satisfaction: 1<=m,n<=10
100% Data satisfaction: 1<=m,n<=50 source
NOIp2008 the third question of improving group
This is the second time to do the first time really silly face of what will not do this ....
And then it's the one that's going to look.
First, you can use the cost stream to do betel pepper Juice Vegetableschinese said will not only DP ...
DP is okay, but there's a condition that you can't have the same person.
If you take the best from top to bottom do not necessarily go back when the best or even may not pass back ...
So what to do.
Now, from the top left to the lower right, go back.
It's equivalent to passing two separate slips of paper from the left. Simultaneous transmission guarantees can be transmitted and not crossed
It's so ingenious ...
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int f[55][55][55];
int m,n,a,b,c,z;
int s[55][55];
int work (int i,int j,int k)
{
if (i<=0| | j<=0| | k<=0| | I+j-k<=0) return 0;
if (f[i][j][k]!=-1) return f[i][j][k];
if (i<=k)
{
f[i][j][k]=0;
return 0;
}
int bu=i+j;;
f[i][j][k]=0;
F[i][j][k]=max (F[i][j][k],work (i-1,j,k) +s[i][j]+s[k][bu-k]);
F[i][j][k]=max (F[i][j][k],work (i-1,j,k-1) +s[i][j]+s[k][bu-k]);
F[i][j][k]=max (F[i][j][k],work (i,j-1,k) +s[i][j]+s[k][bu-k]);
F[i][j][k]=max (F[i][j][k],work (i,j-1,k-1) +s[i][j]+s[k][bu-k]);
return f[i][j][k];
}
int main ()
{
scanf ("%d%d", &m,&n);
for (a=1;a<=m;a++)
for (b=1;b<=n;b++)
scanf ("%d", &s[a][b]);
memset (F,-1,sizeof (f));
Cout<<work (m,n-1,m-1) << ' \ n ';
return 0;
}
Noip rp++