HDU1024 Max Sum plus Plus (DP)

Source: Internet
Author: User

Status: D (I,J) it represents the number of the former J Division number I and includes the first J best results. G (I,j) represents the first J Division number I best results when segment, G (M,N) results are required.

Big Data. A scrolling array is required. Note: This type of int is sufficient, open long long may be tle.

After using the scrolling array, G[j] represents the optimal result divided into the I segment, and the last g[n] is the result

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #define LL __int64#define INF 0x3fffffffusing namespace std;const int MAX = 1e6+5;int a[max];int d[max];int G[MAX ];int Main () {int N,m;//freopen ("D:\\test.txt", "R", stdin), while (~SCANF ("%d%d", &m,&n)) {for    (int i=1;i <=n;i++)    {        scanf ("%d", &a[i]);    }    for (int i=0;i<=n;i++) d[i]=g[i]=0;    int temp=0;    for (int i=1;i<=m;i++)    {for        (int j=i;j<=n;j++)        {            D[j]=max (d[j-1],temp) +a[j];// The first J number is divided into I-1 segment and includes the best result of the number of J            Temp=g[j];   What is the best result                g[j]= (i==j) when divided into i-1 segments?

D[j]:max (G[j-1],d[j]); J number is divided into the best result of I segment } temp=g[i];//i number is divided into i-1 segment of the best results } Cout<<g[n]<<endl; return 0;}



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

HDU1024 Max Sum plus Plus (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.