数据弱,暴力过
题意
N^N的矩阵,求最大子矩阵和
思路
悬线?不需要。暴力+前缀和过
代码
//poj1050 //n^4暴力 #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #define N 105 #define INF 0x3fffffff using namespace std; int a[N][N]; int sum[N]; int ans; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i++) { memset(sym, 0, sizeof(sum)); for (int j = i; j <= n; j++) { int num = 0; for (int k = 1; k <= n; k++) { num += sum[k] += a[j][k]; ans = max(ans, num); if (num < 0) num = 0; } } } printf("%d\n", ans); return 0; }
PS:VS编译坏了,伤心!
原文地址:https://www.cnblogs.com/lincold/p/10162287.html
时间: 2024-11-07 07:47:25