代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[110],s[110],f[110][110];
int re(){
int num=0,fl=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-') fl=-1;ch=getchar();}
while(isdigit(ch)){num=num*10+ch-'0';ch=getchar();}
return num*fl;
}
void pr(int x){
if(x<=9){
long long t=x;
cout<<t;
}
else{
pr(x/10);
long long t=x%10;
cout<<t;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m,ans=0;
n=re();m=re();
s[0]=1;
for(int i=1;i<=m+2;i++){
s[i]=s[i-1]*2;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[j]=re();
}
memset(f,0,sizeof f);
int sum=0;
for(int j=1;j<=m;j++){
for(int k=m;k>=j;k--){
f[j][k]=max(f[j][k],f[j-1][k]+s[m-k+j-1]*a[j-1]);
f[j][k]=max(f[j][k],f[j][k+1]+s[m-k+j-1]*a[k+1]);
}
}
for(int j=1;j<=m;j++){
sum=max(sum,f[j][j]+s[m]*a[j]);
}
ans=ans+sum;
}
pr(ans);
return 0;
}
/*
5 5
0 0 0 0 0
0 0 0 0 1
876 1 566 920 598
259 945 123 659 997
176 478 293 464 278
118214
*/
必关