HDU 2845 Beans (DP)

Source: Internet
Author: User

Problem Descriptionbean-eating is a interesting game, everyone owns an m*n matrix, which are filled with different qualiti Es beans. Meantime, there is the only one bean in any 1*1 grid. Now your want to eat the beans and collect the qualities, but everyone must obey by the following rules:if you eat the BEA n at the coordinate (x, y), you can ' t eat the beans anyway at the coordinates listed (if exiting): (x, Y-1), (x, y+1), and The both rows whose Abscissas are x-1 and x+1.


Now, how much qualities can do you eat and then get?


Inputthere is a few cases. In each case, there is the integer M (row number) and N (column number). The next M lines each contain N integers, representing the qualities of the beans. We can make sure that the quality of beans isn ' t beyond, and 1<=m*n<=200000.
Outputfor the just output the MAX qualities you can eat and then get.
Sample Input

4 611 0 7 5 13 978 4 81 6 22 41 40 9 34 16 1011 22 0 33 39 6

Sample Output
242

Source

Field=problem&key=2009+multi-university+training+contest+4+-+host+by+hdu&source=1&searchmode= SOURCE ">2009 multi-university Training Contest 4-host by HDU

Idea: Pay attention to the state transition equation. There is also the similarity of the transfer equation and the column of the row. And note that the array is bigger.


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace STD; #define N 200005int Dpx[n],dpy[n];int Main () {    int n,m,i,j,s;    while (~SCANF ("%d%d", &n,&m))    {        memset (dpx,0,sizeof (DPX));        memset (dpy,0,sizeof (dpy));        for (i=2;i<=n+1;i++)        {             //memset (dpy,0,sizeof (dpy));             Why this can be stared out, because it will be overwritten for                          (j=2;j<=m+1;j++)            {                scanf ("%d", &s);                Dpy[j]=max (dpy[j-1],dpy[j-2]+s);  Dpy represents the largest number and            }            Dpx[i]=max (Dpx[i-1],dpx[i-2]+dpy[1+m]) that the row can fetch from left to right;  DPX represents the largest and        }        printf ("%d\n", Dpx[n+1]) from which the number can be taken from the above line;    }    return 0;}






Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

HDU 2845 Beans (DP)

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.