VJP1218数字游戏(环形DP)
数据比较小 直接爆了 5重
枚举断开的琏 dp[i][j][k] (i-j)区间为第k段 dp[i][j][k] = min(dp[i][j][k],dp[g][i-1][k-1]*s[i][j])(g<=i-1) s[i][j]为i-j的和
最大值类似 不知道为嘛要加50W 很纳闷 加小了就WA
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #define INF 100000 7 using namespace std; 8 int a[110],dp1[105][105][15],dp2[55][55][15],s[105][105]; 9 int main() 10 { 11 int i,j,k,n,g,o,e,aa,b,c; 12 while(scanf("%d%d",&n,&k)!=EOF) 13 { 14 for(i = 1; i <= n ; i++) 15 scanf("%d",&a[i]); 16 for(i = 1; i <= n ; i++) 17 a[n+i] = a[i]; 18 for(i = 1; i <= 2*n ; i++) 19 { 20 s[i][i] = (a[i]+500000)%10; 21 for(j = i+1 ; j <= 2*n ; j++) 22 s[i][j] = (s[i][j-1]+a[j]+500000)%10; 23 } 24 int minz = INF,maxz=0; 25 for(i = 0; i < n ; i++) 26 { 27 for(aa = 0 ; aa <= k ; aa++) 28 for(c = 0 ; c <= 2*n ; c++) 29 for(b = 0 ; b <= 2*n ; b++) 30 { 31 dp1[c][b][aa] = INF; 32 dp2[c][b][aa] = 0; 33 } 34 for(j = i+1 ; j <= i+n-(k-1) ; j++) 35 { 36 dp1[i+1][j][1] = s[i+1][j]; 37 dp2[i+1][j][1] = s[i+1][j]; 38 } 39 for(j = 2; j <= k ; j++) 40 { 41 for(g = i+j ; g <= i+n-(k-j) ; g++) 42 { 43 for(e = g ; e <= i+n-(k-j) ; e++) 44 { 45 dp1[g][e][j] = INF; 46 for(o = i+j-1 ; o < g ; o++) 47 { 48 dp1[g][e][j] = min(dp1[g][e][j],dp1[o][g-1][j-1]*s[g][e]); 49 dp2[g][e][j] = max(dp2[g][e][j],dp2[o][g-1][j-1]*s[g][e]); 50 } 51 } 52 } 53 } 54 for(j = i+1 ; j <= i+n ; j++) 55 { 56 maxz = max(maxz,dp2[j][i+n][k]); 57 minz = min(minz,dp1[j][i+n][k]); 58 } 59 } 60 printf("%d\n%d\n",minz,maxz); 61 } 62 return 0; 63 }