class Bonus { public: int getMost(vector<vector<int> > board) { // write code here return getMost(board, 0, 0, 0); } int getMost(vector<vector<int> > board, int x, int y, int sum){ sum += board[x][y]; int xrs=0, yrs=0; if (x+1 < 6){ xrs = getMost(board, x+1, y, sum); } if (y+1 < 6) { yrs = getMost(board, x, y+1, sum); } if (xrs==0 && yrs==0) { return sum; } else { return xrs > yrs ? xrs : yrs; } } };
递归穷举所有路线!只保存当前奖励最大值