Advertisement
juanjo12x

UVA_108_Maximum_Sum

Aug 9th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <stack>
  8. #include <queue>
  9. #include <list>
  10. #include <vector>
  11. #include <map>
  12. #include <set>
  13. #include <sstream>
  14. #include <stdlib.h>
  15. #include <cmath>
  16. #define LL unsigned long long
  17. using namespace std;
  18. int dp[105][105];
  19. int main() {
  20.     int n;
  21.     int maxsub=-127*100*100;
  22.     int sub;
  23.     scanf("%d",&n);
  24.     for (int i=0;i<n;i++){
  25.         for(int j=0;j<n;j++){
  26.             scanf("%d",&dp[i][j]);
  27.             if(i>0) dp[i][j]+=dp[i-1][j];
  28.             if(j>0) dp[i][j]+=dp[i][j-1];
  29.             if(i>0 && j>0) dp[i][j]-=dp[i-1][j-1];
  30.         }
  31.     }
  32.     for (int i=0;i<n;i++){
  33.         for(int j=0;j<n;j++){
  34.             for(int k=i;k<n;k++){
  35.                 for(int l=j;l<n;l++){
  36.                   sub=dp[k][l];
  37.                   if(i>0) sub-=dp[i-1][l];
  38.                   if(j>0) sub-=dp[k][j-1];
  39.                   if(i>0 && j>0) sub+=dp[i-1][j-1];
  40.                   maxsub=max(maxsub,sub);
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     printf("%d\n",maxsub);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement