forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1074To the Max.cpp
More file actions
53 lines (50 loc) · 917 Bytes
/
1074To the Max.cpp
File metadata and controls
53 lines (50 loc) · 917 Bytes
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
53
#include <iostream>
using namespace std;
int a[101][101];
int maxsum(int a[],int n)
{
int sum=-10000000,b=0;
int i;
for(i=0;i<n;i++)
{
if (b>0)
b+=a[i];
else
b=a[i];
if(b>sum)
sum=b;
}
return sum;
}
int maxsum2(int m,int n)
{
int sum = -10000000;
int i,j,k,max;
int* b = new int[n+1];
for (i=0;i<m;i++)
{
for(k=0;k<n;k++)
b[k]=a[i][k];
max = maxsum(b,n);
if(max>sum)
sum=max;
for(j=i+1;j<m;j++)
{
for (k=0;k<=n;k++)b[k]+=a[j][k];
max = maxsum(b,n);
if(max>sum)sum=max;
}
}
delete []b;
return sum;
}
int main()
{
int n,i,j;
cin >> n;
for (i=0;i<n;i++)
for (j=0;j<n;j++)
cin >> a[i][j];
cout << maxsum2(n,n) << endl;
return 0;
}