HDU1081 To The Max
Posted yanyiming10243247
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU1081 To The Max相关的知识,希望对你有一定的参考价值。
二维前缀和 || 类子序列和的DP
后者快,压二维为一维的方法
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 6 using namespace std; 7 8 const int N = 108; 9 int n, ans = -2147483633, up[N][N], dp[N], a, b[N]; 10 11 int main() 12 { 13 while (~scanf("%d", &n)) 14 { 15 ans = -2147483633; 16 for (int i = 1; i <= n; ++i) 17 for (int j = 1; j <= n; ++j) 18 scanf("%d", &a), up[i][j] = a + up[i - 1][j]; 19 for (int line = 1; line <= n; ++line) 20 for (int high = 1; high <= line; ++high) 21 { 22 for (int i = 1; i <= n; ++i) 23 dp[i] = 0, b[i] = up[line][i] - up[high - 1][i]; 24 for (int i = 1; i <= n; ++i) 25 dp[i] = max(dp[i - 1], 0) + b[i], ans = max(dp[i], ans); 26 } 27 printf("%d ", ans); 28 } 29 return 0; 30 }
以上是关于HDU1081 To The Max的主要内容,如果未能解决你的问题,请参考以下文章
HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)