阶段:共走m+n-2步,共有m+n-2个阶段 (因为左上角起点坐标为(1,1))
状态:
for(int k=1;k<m+n-2;k++)//阶段
t=k+2>m?m:k+2;
for(int i=1;i<=t;i++)//第一个纸条的状态
for(int j=i+1;j<=t;j++)//第二个纸条的状态
#include <cstdio>
#include<cstring>
int max(int a, int b) { return (a > b ? a : b); }
using namespace std;
int v[52][52];
int f[102][52][52];
int main()
{
int T = 1, m, n, c, t;
while (T--)
{
memset(v, 0, sizeof(v));
memset(f, 0, sizeof(f));
scanf("%d", &m);
scanf("%d", &n);
c = m + n - 2;
for (int i = 1;i <= m;i++)
for (int j = 1;j <= n;j++)
scanf("%d", &v[i][j]);
for (int k = 1;k<c;k++)
{
t = k + 2>m ? m : k + 2;
for (int i = 1;i <= t;i++)
for (int j = i + 1;j <= t;j++)
if (i != j)
f[k][i][j] = max(max(f[k - 1][i - 1][j], f[k - 1][i][j - 1]), max(f[k - 1][i][j], f[k - 1][i - 1][j - 1]))
+ v[i][k - i + 2] + v[j][k - j + 2];
}
f[c][m][m] = max(f[c - 1][m - 1][m], f[c - 1][m][m - 1]);
printf("%d
", f[c][m][m]);
}
}
转自:http://blog.csdn.net/epiker/article/details/7482875