0%

[題解]農作物採收問題

a144. 農作物採收問題

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define double long double
#define N 25
#define Orz ios::sync_with_stdio(0),cin.tie(0)
#define INF 2e18
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define rrep(i,l,r) for(int i=l;i<r;i++)
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
int n,num[N][N],dp[N][N];

void init(){
memset(num,0,sizeof(num));
memset(dp,0,sizeof(dp));
}

signed main(){
init();
cin>>n;
rep(i,1,n)rep(j,1,n)cin>>num[i][j];

for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
num[i][j]+=num[i-1][j]+num[i][j-1]-num[i-1][j-1];
}
}
int ans = 0;

//左上(a,b)右下(x,y)
rep(i,1,n)rep(j,1,n)rep(a,1,i)rep(b,1,j)
ans = max(ans,num[i][j]-num[a-1][j]-num[i][b-1]+num[a-1][b-1]);

cout<<ans<<endl;
}