1. 程式人生 > 其它 >2022蘋果春季釋出會帶來新款iPhoneSE價格預計2500左右

2022蘋果春季釋出會帶來新款iPhoneSE價格預計2500左右

package leetcode;

public class offer_47 {
    public int maxValue(int[][] grid) {
        int hight=grid.length;
        int width=grid[0].length;
        int[][] dp=new int[hight][width];
        for(int i=0;i<hight;i++) {
            for(int j=0;j<width;j++) {
                if(i==0&&j==0) {
                    dp[i][j]
=grid[0][0]; continue; } if(i==0) { dp[i][j]=dp[i][j-1]+grid[i][j]; continue; } if(j==0) { dp[i][j]=dp[i-1][j]+grid[i][j]; continue; } dp[i][j]
=Math.max(dp[i-1][j], dp[i][j-1])+grid[i][j]; } } return dp[hight-1][width-1]; } public static void main(String[] args) { // TODO Auto-generated method stub offer_47 off=new offer_47(); int[][] grid= { {1,3,1}, {
1,5,1}, {4,2,1} }; System.out.println(off.maxValue(grid)); } }