[algorithm] year-end award

Source: Internet
Author: User

"Reprint: http://blog.csdn.net/codeemperor/article/details/51068478"

Small East Company to send the year-end award, and small east just got the highest welfare, he wants to participate in a lottery game in the company annual meeting, the game on a 6*6 board, on the top of the 36 value of the gift, each small board placed a gift, he needs to start from the upper left corner of the game, Can only move down or to the right one step at a time, to reach the lower right corner stop, along the side of the lattice gift small East can get, please design an algorithm so that small east to get the highest value gift.
Given a 6*6 matrix board, where each element is the gift value of the corresponding lattice, and the upper-left corner is [0,0], return the maximum value that can be obtained, guaranteeing that each gift is worth more than 100 less than 1000.

Investigate dynamic Planning:

1 ImportJava.util.*;2 3  Public classBonus {4      Public intGetmost (int[] board) {5         //Write code here6         intn =board.length;7         int[] DP =New int[n][n];8Dp[0][0] = board[0][0];9          for(inti = 1; I < n; i++) {           TenDp[0][i] = dp[0][i-1]+board[0][i]; OneDp[i][0] =dp[i-1][0]+board[i][0]; A  -         } -          for(inti = 1; I < n; i++) { the              for(intj = 1; J < N; J + +) { -DP[I][J] = Math.max (Dp[i-1][j], dp[i][j-1]) +Board[i][j]; -             } -         } +         returnDp[n-1][n-1]; -     } +}

[algorithm] year-end award

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.