标签:nbsp stream i++ sizeof str memset nod cin color
思路:
dp。
实现:
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 typedef long long ll; 7 8 int n, m, a[505][505], dp[505]; 9 ll b[505]; 10 11 ll solve(ll * c) 12 { 13 ll sum = 0, maxnn = 0; 14 for (int l = 0; l < m; l++) 15 { 16 sum += c[l]; 17 if (sum < 0) 18 sum = 0; 19 if (sum > maxnn) 20 maxnn = sum; 21 } 22 return maxnn; 23 } 24 25 int main() 26 { 27 cin >> m >> n; 28 for (int i = 0; i < n; i++) 29 for (int j = 0; j < m; j++) 30 cin >> a[i][j]; 31 ll maxn = 0; 32 for (int i = 0; i < n; i++) 33 { 34 memset(b, 0, sizeof(b)); 35 for (int j = i; j < n; j++) 36 { 37 for (int k = 0; k < m; k++) 38 { 39 b[k] += a[j][k]; 40 } 41 ll s = solve(b); 42 maxn = max(maxn, s); 43 } 44 } 45 cout << maxn << endl; 46 return 0; 47 }
标签:nbsp stream i++ sizeof str memset nod cin color
原文地址:http://www.cnblogs.com/wangyiming/p/6657367.html