| 记录编号 |
593224 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
4006.Partition |
最终得分 |
100 |
| 用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
3.714 s |
| 提交时间 |
2024-08-27 19:54:17 |
内存使用 |
102.96 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 2e3+10;
const ll inf = 1e18;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m;
ll a[N][N],f[N][N],g[N][N],s[N][N],ans;
int main(){
freopen("partition.in","r",stdin);
freopen("partition.out","w",stdout);
n = read(),m = read();
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)a[i][j] = read(),ans += a[i][j];
for(int i = n;i >= 1;i--)
for(int j = 1;j <= m;j++)s[i][j] = s[i+1][j] + a[i][j];
memset(f,-0x7f,sizeof f);
memset(g,-0x7f,sizeof g);
f[0][1] = g[0][m+1] = 0;
for(int i = 0;i <= n+1;i++)f[i][1] = g[i][m+1] = 0;
for(int i = 1;i <= n+1;i++){
for(int j = 2;j <= m+1;j++)f[i][j] = max(f[i-1][j],f[i][j-1] + s[i][j-1]);
for(int j = m;j >= 1;j--)g[i][j] = max(g[i-1][j],g[i][j+1] + s[i][j]);
}
printf("%lld\n",ans + 2ll * f[n+1][m+1] + g[n+1][1]);
return 0;
}