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 |
#include<iostream> using
namespace std; int Sum( int
i, int k, int j, int l, int a[3][4]) { int
sum=0; for ( int
c=i;c<=k;c++) { for ( int
d=j;d<=l;d++) { sum=sum+a[c][d]; } } return
sum; } void
main() { int
a[3][4]={ 1,2,3,0, 0,-4,-5,-6, 7,0,-8,9}; int
i,j,k,l; int
max,num; max=a[0][0]; for (i=0;i<3;i++) { for (k=i;k<3;k++) { for (j=0;j<4;j++) { for (l=j;l<4;l++) { num=Sum(i,k,j,l,a); cout<<num<< " " ; if (num>max) max=num; } } } } cout<<max; } |
二维数组求最大子数组(刘若凡 刘梦辉),布布扣,bubuko.com
原文:http://www.cnblogs.com/lrffln/p/3639140.html