HDU 2845 Beans (maximum discontinuous subsequence and) (compression solver)

Source: Internet
Author: User

Test instructions: Take a number in the figure, for example, after taking 81, the same row of adjacent two can not be taken, there are 81 of the above row and the following line can not be taken, asked to get the maximum and how much.

The main point: the maximum value that a row can obtain, and then the maximum value that can be obtained by all rows.

#include <set> #include <map> #include <stack> #include <queue> #include <deque> #include & lt;cmath> #include <vector> #include <string> #include <cstdio> #include <cstdlib> #include &
lt;cstring> #include <iostream> #include <algorithm> using namespace std; #define L (i) i<<1 #define R (i) i<<1|1 #define INF 0x3f3f3f3f #define PI ACOs ( -1.0) #define EPS 1e-9 #define M
AXN 200010 #define MOD 1000000007 int DPX[MAXN],DPY[MAXN];

int n,m;
    int main () {int t;
    scanf ("%d", &t);
        while (scanf ("%d%d", &n,&m)! = EOF) {memset (dpx,0,sizeof (DPX));
        memset (dpy,0,sizeof (dpy)); for (int i = 2, I <= n+1; i++) {for (int j = 2; J <= M+1; j + +) {int
                X
                scanf ("%d", &x);
            DPX[J] = max (dpx[j-2]+x,dpx[j-1]);
        } Dpy[i] = max (dpy[i-2]+dpx[m+1],dpy[i-1]);
        }printf ("%d\n", dpy[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.