iscsi

SRM 513 D2 1000 CutTheNumbers

Jul 28th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. using namespace std;
  14. typedef long long LL;
  15. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  16. #define REP(k,a) for(int k=0; k < (a); ++k)
  17.  
  18.  
  19. class CutTheNumbers {
  20.     vector<vector<int> > mBoard;
  21.     int calc(int x1, int x2, int y1, int y2)
  22.     {
  23.         int res=0,res2=0,tmp=0;
  24.         FOR(i,x1,x2)
  25.         {
  26.             tmp=0;
  27.             FOR(j,y1,y2)
  28.             {
  29.                 tmp*=10;
  30.                 tmp+=mBoard[i][j];
  31.             }
  32.             res+=tmp;
  33.         }
  34.         FOR(j,y1,y2)
  35.         {
  36.             tmp=0;
  37.             FOR(i,x1,x2)    
  38.             {
  39.                 tmp*=10;
  40.                 tmp+=mBoard[i][j];
  41.             }
  42.             res2+=tmp;
  43.         }
  44.         res=max(res,res2);
  45.         FOR(i,x1+1,x2)
  46.             res=max(res,calc(x1,i,y1,y2)+calc(i,x2,y1,y2));
  47.         FOR(i,y1+1,y2)
  48.             res=max(res,calc(x1,x2,y1,i)+calc(x1,x2,i,y2));
  49.         return res;
  50.     }
  51. public:
  52.     int maximumSum(vector <string> board) {
  53.         int n=board.size();
  54.         int m=board[0].size();
  55.         mBoard.resize(n,vector<int> (m));
  56.         REP(i,n)
  57.         REP(j,m)
  58.         {
  59.             mBoard[i][j]=board[i][j]-'0';
  60.         }
  61.         return calc(0,n,0,m);
  62.     }
  63.  
  64. };
Advertisement
Add Comment
Please, Sign In to add comment