标签:
3 3
0 3 9
2 8 5
5 7 0
34
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; int n,m,v[55][55],f[105][55][55]; int main(){ cin>>m>>n; for(int i = 1;i <= m;i++){ for(int j = 1;j <= n;j++){ scanf("%d",&v[i][j]); } } for(int l = 2;l <= n+m;l++) for(int y = 1;y <= m && y < l;y++){ for(int i = 1;i <= m && i < l;i++){ int x = l - y, j = l - i; f[l][i][y] = max(max(f[l-1][i][y],f[l-1][i-1][y]),max(f[l-1][i][y-1],f[l-1][i-1][y-1])); f[l][i][y] += v[i][j]; if(!(i == y && j == x)) f[l][i][y] += v[y][x]; } } cout<<f[m+n][m][m]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5754634.html