hdu2686

maksyuki 发表于 oj 分类,标签:
0

Matrix

Problem Description

Yifenfei very like play a number game in the n*n Matrix. A positive integer number is put in each area of the Matrix.
Every time yifenfei should to do is that choose a detour which frome the top left point to the bottom right point and than back to the top left point with the maximal values of sum integers that area of Matrix yifenfei choose. But from the top to the bottom can only choose right and down, from the bottom to the top can only choose left and up. And yifenfei can not pass the same area of the Matrix except the start and end.

Input

The input contains multiple test cases.
Each case first line given the integer n (2<n<30)
Than n lines,each line include n positive integers.(<100)

Output

For each test case output the maximal values yifenfei can get.

Sample Input

2

10 3

10

3

10 3 3

2 5 3

6 7 10

5

1 2 3 4 5

2 3 4 5 6

3 4 5 6 7

4 5 6 7 8

5 6 7 8 9

Sample Output

28

46

80

Author

yifenfei

Source

ZJFC 2009-3 Programming Contest

 

题目类型:多线程DP

算法分析:使用dp[i][j][k][q]表示两个点分别到达(i,j)和(k,p)时所获得的最大数,然后直接递推,最后输出dp[n][n][n][n]的值即可