京东-年终奖

年终奖

http://www.nowcoder.com/questionTerminal/72a99e28381a407991f2c96d8cb238ab

思路

递归dp回溯
dp[i][j]+max(getMost(i-1,j),getMost(i,j-1)),状态转移方程

代码

import java.util.*;
public class Bonus {
    public int getMost(int[][] board,int i,int j) {
        // write code here
        if(i==0 && j==0){return board[0][0];}
        if(i==0){return board[i][j]+getMost(board,i,j-1);}
        if(j==0){return board[i][j]+getMost(board,i-1,j);}
        return board[i][j]+Math.max(getMost(board,i-1,j),getMost(board,i,j-1));
    }

    public int getMost(int[][] board) {
        // write code here
        return getMost(board,5,5);
    }   
}
全部评论

相关推荐

04-10 11:56
如皋中学 Java
高斯林的信徒:双c9能简历挂的?
点赞 评论 收藏
分享
求面试求offer啊啊啊啊:要求太多的没必要理
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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