Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
53 lines (45 loc) · 1.1 KB

File metadata and controls

53 lines (45 loc) · 1.1 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#define MAXN 120
#define INF 99999999
using namespace std;
int N, data[MAXN][MAXN], c[MAXN][MAXN];
void work(){
//compress matrix here
for(int i=0; i<N; i++)for(int j=0; j<N; j++)c[i][j]=data[i][j];
for(int j=0; j<N; j++){
for(int i=1; i<N; i++){
c[i][j]+=c[i-1][j];
}
}
//c[i][j] represent the accumutive sum of c[0~i][j]
int ans = -INF;
for(int i=0; i<N; i++){
for(int j=i; j<N; j++){
int t_sum = 0;
int t_dp[MAXN];
memset(t_dp,0,sizeof(t_dp));
for(int k=0; k<N; k++){
int t = c[j][k] - c[i][k] + data[i][k];
if(k==0){
t_dp[0] = max(0, t);
}else{
t_dp[k] = max(t_dp[k-1]+t, t);
}
if(t_dp[k]> ans ){
ans = t_dp[k];
}
}
}
}
cout<<ans<<endl;
}
int main(){
cin>>N;
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
cin>>data[i][j];
}
}
work();
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.