题意: 求最大子矩阵和 解法: DP AC代码如下: /* Author: ACb0y Date: 2010年12月6日22:02:34 Type: 最大子矩阵和 ProblemID: HDU 1081 Result: 3291421 2010-12-06 21:47:45 Accepted 1081 31MS 268K 953 B C++ ACb0y */ #include <stdio.h> #include <string.h> #define max(a, b) (a) > (b) ? (a) : (b) int d[101][101]; int Max(int * a, int n) { int d[102]; d[0] = a[0]; int max = d[0]; for (int i = 1; i < n; ++i) { d[i] = max(d[i - 1] + a[i], a[i]); if (d[i] > max) { max = d[i]; } } return max; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n; while (scanf("%d", &n) != EOF) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { scanf("%d", &d[i][j]); } } int ans = d[0][0]; int a[101]; memset(a, 0, sizeof(a)); for (int i = 1; i <= n; ++i) { for (int j = i; j <= n; ++j) { memset(a, 0, sizeof(a)); for (int k = 1; k <= n; ++k) { for (int l = i; l <= j; ++l) { a[k] += d[l][k]; } } int temp = Max(a, n); if (temp > ans) { ans = temp; } } } printf("%d/n", ans); } return 0; }