1. 程式人生 > >合肥工業大學oj p1012

合肥工業大學oj p1012

memset mes col ring sin iostream fin string turn

#include <iostream>
#include <cstring>
#define maxn 5 + 2
using namespace std;

int m, n, G[maxn][maxn], dp[maxn][maxn][maxn][maxn];

int main()
{
    while (cin >> m >> n && m && n)
    {
        memset(G, 0, sizeof(G));
        memset(dp, 0, sizeof(dp));
        
for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) cin >> G[i][j]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) for (int k = 1; k <= n; ++k) { int l = i + j - k;
if (l >= 1) dp[i][j][k][l] = G[i][j] + G[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])); else continue; if(i == k && j == l) dp[i][j][k][l]
-= G[i][j]; } cout << dp[n][m][n][m] << endl; } return 0; }

合肥工業大學oj p1012