1 solutions
-
1
四层循环竟然能过把第i到j行的每一列加起来,再求最大子序列即可#include <cstdio> #include <algorithm> #include <cmath> int n, ans=-999999999; int a[200][200], f[200]; int main() { std::cin >> 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 ++) { for(int j = i; j <= n; j ++) { for(int k = 1; k <= n; k ++) { f[k] = 0; for(int z = i; z <= j; z++ ) { f[k] = f[k] + a[z][k]; } } int maxn = -999999999; for(int k = 1; k <= n; k ++) { f[k] = std::max(f[k], f[k - 1] + f[k]); maxn = std::max(f[k], maxn); } ans = std::max(ans, maxn); } } std::cout << ans; return 0; }
- 1
Information
- ID
- 687
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 2
- Tags
- # Submissions
- 13
- Accepted
- 6
- Uploaded By