hdoj-2571-Destiny "Dynamic Planning"

Source: Internet
Author: User

FateTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 12611 Accepted Submission (s): 4401


Problem description through the valley means that the lemon of the great Lord has been infinitely close!
But who can think, Yifenfei in kill some cats, but again face the fate of the maze of the test, this is the Devil lemon set up another organ. You know, whoever, if trapped in the maze for more than 1 hours, will surely die!
Poor Yifenfei in order to save mm, righteousness without return to jump into the maze. Let us help to help the persistent him!
The great maze of destiny can be seen as a two-dimensional grid array, as shown in:

Yifenfei first in the upper left corner, the aim of course is to reach the lower right corner of the great Lord's seat. Every lattice in the maze is cursed by the goddess of luck or the devil, so each grid corresponds to a value, where it automatically gets the corresponding value.
It is now stipulated that Yifenfei can only go to the right or down and only one grid at a time. But if you go to the right, you can walk one block at a time or go to the number of columns that are currently in the number of columns, that is: if the current lattice is (x, y), the next step can be (x+1,y), (x,y+1) or (x,y*k) where k>1.
In order to be able to best grasp the eradication of the Devil Lemon,yifenfei hope to be able to get the greatest fortune in this maze of fate.


Input data is first an integer c, which represents the number of groups of test data.
The first line of each set of test data is two integer n,m, representing the number of rows and columns (1<=n<=20,10<=m<=1000);
followed by n rows of data, each containing M integers representing the lucky value K (|k|<100) for the lattice of the N row M column.

Output match each set of test data with an integer that represents the maximum lucky value that Yifenfei can get.
Sample Input
13 89 10 10 10 10-10 10 1010-11-1 0 2 11 10-20-11-11 10 11 2 10-10-10

Sample Output
52

Authoryifenfei
SOURCEACM Program Design Final Exam 081230
Recommendyifenfei | We have carefully selected several similar problems for you:1421 2159 1171 1505 1506

#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;const int inf=-1< <30;int A[25][1010],dp[25][1010];int Main () {int c;scanf ("%d", &c), while (c--) {int n,m,i,j,k,maxn;scanf ("%d%d") , &n,&m); for (I=1;i<=n;++i) {for (j=1;j<=m;++j) {scanf ("%d", &a[i][j]);}} Memset (Dp,0,sizeof (DP)); for (j=0;j<=m;++j) for (i=0;i<=n;++i) dp[i][j]=inf;dp[1][1]=a[1][1];for (i=1;i<=n; ++i) {for (j=1;j<=m;++j) {              Dp[i+1][j]=max (dp[i+1][j],dp[i][j]+a[i+1][j]);              Dp[i][j+1]=max (dp[i][j+1],dp[i][j]+a[i][j+1]);              for (k=2;k*j<=m;++k) {              Dp[i][k*j]=max (dp[i][k*j],dp[i][j]+a[i][k*j]);}}}            printf ("%d\n", Dp[n][m]);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdoj-2571-Destiny "Dynamic Planning"

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.