显示代码纯文本
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int max(int a,int b){return a>b?a:b;}
struct LL
{
int num[50];int len;
LL()
{
memset(num,0,sizeof(num));len=0;
}
LL(int x)
{
memset(num,0,sizeof(num));len=1;
num[1]=x;
while(num[len]>=10)
{
num[len+1]=num[len]/10;
num[len]%=10;
++len;
}
}
LL operator +(const LL &B)const
{
LL C;
C.len=max(len,B.len);
for(int i=1;i<=C.len;++i)
C.num[i]=num[i]+B.num[i];
for(int i=1;i<=C.len;++i)
{
if(C.num[i]>=10)
{
C.num[i+1]++;
C.num[i]-=10;
if(i==C.len)C.len++;
}
}
return C;
}
LL operator *(int x)const
{
LL B;
B.len=len;
for(int i=1;i<=len;++i)
B.num[i]=num[i]*2;
for(int i=1;i<=B.len;++i)
{
if(B.num[i]>=10)
{
B.num[i+1]+=B.num[i]/10;
B.num[i]%=10;
if(i==B.len)B.len++;
}
}
return B;
}
bool operator >(const LL &B)const
{
if(len!=B.len)return len>B.len;
else
{
for(int i=len;i>=1;--i)
if(num[i]!=B.num[i])
return num[i]>B.num[i];
return false;
}
}
void output()
{
for(int i=len;i>=1;--i)
printf("%d",num[i]);
}
}ans;
LL max(LL a,LL b){return a>b?a:b;}
int Main()
{
freopen("game.in","r",stdin);freopen("game.out","w",stdout);
scanf("%d%d",&n,&m);
for(int k=1;k<=n;k++)
{
int pic[81];
LL f[81][81];
memset(f,0,sizeof(f));
for(int i=1;i<=m;i++)scanf("%d",&pic[i]);
for(int i=1;i<=m;i++)f[i][i]=pic[i];
for(int len=1;len<m;len++)for(int i=1;i+len<=m;i++)
{
int j=i+len;
LL tmp1=f[i+1][j]*2+f[i][i],tmp2=f[i][j-1]*2+f[j][j];
f[i][j]=max(tmp1,tmp2);
}
ans=ans+f[1][m];
}
ans=ans*2;
ans.output();
return 0;
}
int main(){;}
int syy=Main();