#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 122; const int INF = 2147483640; int dp[maxn], temp[maxn]; int a[maxn][maxn]; int n; int solve(); int main() { scanf("%d", &n); int i, j; for(i = 1; i <= n; ++i) for(j = 1; j <= n; ++j) { scanf("%d", &a[i][j]); } int ans = solve(); printf("%d\n", ans); return 0; } int solve() { int i, j, k; int ret = -INF; for(i = 1; i <= n; ++i)//枚举行的起点 { memset(temp, 0, sizeof(temp)); for(j = i; j <= n; ++j)//枚举行的终点 { for(k = 1; k <= n; ++k)//i~j行,第k列的值,压缩维度 temp[k] += a[j][k]; memset(dp, 0, sizeof(dp)); for(k = 1; k <= n; ++k)//dp_最长连续子序列和 { dp[k] = max(temp[k], dp[k-1]+temp[k]); ret = max(ret, dp[k]);l } } } return ret; }
洛谷P1719_最大加权矩阵和模板
猜你喜欢
转载自blog.csdn.net/jay__bryant/article/details/80150889
今日推荐
周排行