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)