#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
const double eps = 1e-10;
const double pi = acos(-1);
const int maxn = 100 + 10;
const int maxm = (maxn<<5) + 5;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
int n, m;
__int128 dp[maxn][maxn][maxn], a[maxn][maxn];
__int128 ans;
inline __int128 Max(__int128 x, __int128 y){return (x > y) ? x : y;}
inline __int128 read()
{
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void write(__int128 x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
int main()
{
scanf("%d %d", &n, &m);
ans = 0;
for(int i = 1 ; i <= n ; ++ i){
for(int j = 1 ; j <= m ; ++ j){
a[i][j] = read();
}
}
for(int i = 1 ; i <= n ; ++ i)
for(int j = 1 ; j <= m ; ++ j)
dp[i][j][j] = a[i][j] * 2;
for(int i = 1 ; i <= n ; ++ i){
for(int len = 2 ; len <= m ; ++ len){
for(int l = 1 ; l + len - 1 <= m ; ++ l){
int r = l + len - 1;
dp[i][l][r] = Max(dp[i][l][r], Max(dp[i][l][r-1] * 2 + a[i][r] * 2, dp[i][l+1][r] * 2 + a[i][l] * 2));
}
}
ans += dp[i][1][m];
}
write(ans);
return 0;
}
洛谷P1005 矩阵取数游戏(附__int128版本)(区间dp入门)
最新推荐文章于 2021-12-12 21:14:39 发布