Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴一下,诸位给点优化建议#include <iostream> using namespace std; int map[110][110]; int sum[110][110]; int getsum(int w, int x, int y, int z) { return sum[y][z] + sum[w - 1][x - 1] - sum[w - 1][z] - sum[y][x - 1]; } int main() { int ans = -100000; int m; cin >> m; for(int i = 1; i <= m; i++) for (int j = 1; j <= m; j++) { cin >> map[i][j]; sum[i][j] = map[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; } for(int i=1;i<=m;i++) for (int j = i; j <= m; j++) { int ttt = 0; for (int t = 1; t <= m; t++) { if (ttt > 0) ttt += getsum(i, t, j, t); else ttt = getsum(i, t, j, t); if (ttt > ans) ans = ttt; } } cout << ans << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator