题解 | #年终奖#

年终奖

https://www.nowcoder.com/practice/72a99e28381a407991f2c96d8cb238ab

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;
        }
    }
    
};

递归穷举所有路线!只保存当前奖励最大值

全部评论

相关推荐

测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务