Question 1529: Board hunting-jiudu

Source: Internet
Author: User
Description:

There is now an 8*8 board with 64 gifts of varying value on it. Each small board has a gift (the value of the gift is greater than 0 and less than 1000 ), A person's initial position is in the upper left corner of the board. Each time he can only move one step down or to the right, and take away the gift from the corresponding board. The ending position is in the lower right corner of the Board, design an algorithm to maximize the value of your gift.

Input:

The input contains multiple test cases. Each test case has eight rows and eight columns. The number in column J of row I represents the value of the gift on the board, separate Two numbers with spaces.

Output:

For each group of test cases, please output the gift that gives you the maximum value.

Sample input:
2 8 15 1 10 5 19 193 5 6 6 2 8 2 1216 3 8 17 12 5 3 1413 3 2 17 19 16 8 712 19 10 13 8 20 16 154 12 3 14 14 5 2 1214 9 8 5 3 18 18 204 2 10 19 17 16 11 3
Sample output:
194

Recommendation index :※

Source: http://ac.jobdu.com/problem.php? PID = 1, 1529

DP

#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;#define  max(a,b) ((a)>(b)?(a):(b))const int N=9;int board[N][N];int val[N][N];int find_max_value(int n){int i,j;for(i=1;i<=n;i++){for(j=1;j<=n;j++){val[i][j]=max(val[i-1][j],val[i][j-1])+board[i][j];}}return val[n][n];}int main(){int  i,j;while(true){memset(board,0,sizeof(board));memset(val,0,sizeof(val));for(i=1;i<N;i++){for(j=1;j<N;j++){if(scanf("%d",&board[i][j])==EOF)return 0;}}printf("%d\n",find_max_value(N-1));}return 0;}

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.