标签:sub space accept printf rect function nts time gre
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12697 Accepted Submission(s):
6090
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm> #include<string> #include<set> #include<map> #include<vector> #include<queue> #include<functional> using namespace std; const int N_MAX= 100+2; int a[N_MAX][N_MAX]; int sum[N_MAX][N_MAX]; int main() { int n; while (scanf("%d", &n) != EOF) { memset(sum,0,sizeof(sum)); memset(a, 0,sizeof(a)); for (int i = 0; i < n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &a[i][j]); } } for (int i = 0; i < n; i++) { for (int j = 1; j <= n; j++) { sum[i][j] =sum[i][j-1]+ a[i][j]; } } int res = -INT_MAX; for (int i = 0; i < n; i++) {//固定i,j for (int j = i+1; j <= n; j++) { int S = 0; for (int k = 0; k < n; k++) { S += sum[k][j]-sum[k][i-1];//累加上闭区间[i,j]值的和 if (S > res) res = S; if (S < 0)S = 0; } } } printf("%d\n",res); } return 0; }
标签:sub space accept printf rect function nts time gre
原文地址:http://www.cnblogs.com/ZefengYao/p/6686980.html