AcWing 275. 提高课 传纸条
原题链接
中等
作者:
我需要0失误
,
2022-07-05 11:55:39
,
所有人可见
,
阅读 118
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 55;
int w[N][N];
int f[N][N][N][N];
int main()
{
int n,m;
cin>>n>>m;
int x,y,z;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>w[i][j];
for(int i1=1;i1<=n;i1++)
for(int j1=1;j1<=m;j1++)
for(int i2=1;i2<=n;i2++)
for(int j2=1;j2<=m;j2++)
{
int temp;
if(i1==i2&&j1==j2)
temp = w[i1][j1];
else
temp = w[i1][j1]+w[i2][j2];
int &x = f[i1][j1][i2][j2];
x = max(x,f[i1-1][j1][i2-1][j2]+ temp);
x = max(x,f[i1-1][j1][i2][j2-1]+ temp) ;
x = max(x,f[i1][j1-1][i2-1][j2]+ temp) ;
x = max(x,f[i1][j1-1][i2][j2-1]+ temp) ;
}
cout<<f[n][m][n][m];
return 0;
}