Ok...
Topic link: https: //www.luogu.org/problem/P1880
This question is characterized by a gravel ring, so let a [i + n] = a [i] (twice the length) of the ring to solve the problem, then note the minimum time interval required to be initialized to a large dp the number ...
AC Code:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 6 using namespace std; 7 8 int dp1[205][205], dp2[205][205], sum[205], a[205]; 9 10 int main(){ 11 int n; 12 scanf("%d", &n); 13 for(int i = 1; i <= n; i++) {scanf("%d", &a[i]); a[i + n] = a[i];} 14 for(int i = 1; i <= n * 2; i++) {sum[i] = sum[i - 1] + a[i];} 15 for(int l = 1; l <= n; l++){ 16 for(int i = 1; i <= 2 * n; i++){ 17 int j = i + l; 18 dp2[i][j] = 0x3f3f3f;//Initialized for the minimum lot . 19 IF (J> 2 * n-) BREAK ; 20 is for ( int K = I; K <J; K ++ ) { 21 is DP1 [I] [J] = max (DP1 [I] [J ], DP1 [I] [K] + DP1 [K + . 1 ] [J] + SUM [J] - SUM [I - . 1 ]); 22 is DP2 is [I] [J] = min (DP2 is [I] [J ], DP2 is [I] [K] + DP2 is [K + . 1 ] [J] + SUM [J] - SUM [I - . 1 ]); 23 is } 24 } 25 } 26 is int Maxx = 0 , Minn = 0x3f3f ; 27 for(int i = 1; i <= n; i++){ 28 int j = i + n - 1; 29 maxx = max(maxx, dp1[i][j]); 30 minn = min(minn, dp2[i][j]); 31 } 32 printf("%d\n%d\n", minn, maxx); 33 return 0; 34 }