Topic Link: Click to enter
The last time I did a similar, but only one at a time. This rule can be multiple at a time. Define state Dp[i][j] represents the maximum fraction that can be obtained when facing the interval (i,j), and then Dp[i][j]=max (sum[i+k][j]-dp[i+k][j]+sum I [I-k+1],sum[i][j-k]-dp[i][j-k]+sum[j-k+1][j]). Synthesis is dp[i][j]=sum[i][j]-min (Dp[i+k][j],dp[i][j-k]). where Sum[i][j] Represents the sum of the interval (i,j), 1<=k<=j-i+1. This topic is better with memory word search.
The code is as follows:
#include <iostream>#include <cstdio>#include <cstring>using namespace STD;#define MAXN#define INF 0x3f3f3f3fintA[MAXN],SUM[MAXN][MAXN];intD[MAXN][MAXN];intdpintIintj) {int& Ans=d[i][j];if(ans>-1*inf)returnAnsif(J<i)return 0; ans=-1*inf; for(intk=1; k<=j-i+1; k++) Ans=max (Sum[i][j]-min (DP (I+K,J), DP (I,J-K)), ans);returnAns;}intMain () {intN Freopen ("In.txt","R", stdin); while(scanf("%d", &n) &&n) { for(intI=1; i<=n;i++)scanf("%d", &a[i]); for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) d[i][j]=-1*inf;memset(Sum,0,sizeof(sum)); for(intI=1; i<=n;i++) for(intj=i;j<=n;j++) sum[i][j]=sum[i][j-1]+A[J];intANS=DP (1, n);printf("%d\n", ans*2-sum[1][n]); }return 0;}
UVA 10891--game of sum+ classic DP