题意:




思路:






#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

const int M = 1005;
const int N = 85;
__int128 read(){
    __int128 x=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')f=-1;
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void print(__int128 x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
int n,m;
__int128 f[M][M],g[M],a[M];
void init(){
    g[0] = 1;
    for(int i = 1;i <= m;i++){
        g[i] = g[i - 1] * 2;
    }

}
int main(){
    scanf("%d%d",&n,&m);
    init();
    __int128 ans = 0;
    for(int i = 1;i <= n;i++){
        memset(f,0,sizeof(f));
        for(int j = 1;j <= m;j++){
            a[j] = read();
        }
        for(int len = m;len >= 1;len--){
            for(int i = 1;i+len-1 <= m;i++){
                int j = i + len - 1;
                f[i][j] = max(f[i][j], f[i - 1][j] + g[m - j + i - 1] * a[i - 1]); 
                f[i][j] = max(f[i][j], f[i][j + 1] + g[m - j + i - 1] * a[j + 1]);
            }
        }
        __int128 mx = 0;
        for(int i = 1;i <= m;i++){
            mx = max(mx,f[i][i] + g[m] * a[i]);
        }
        ans = ans + mx;
    }
    print(ans);
    return 0;
}