|
- #include<iostream>
- using namespace std;
- int n,k,a[20],dp[20][20],s[20];
- int i,j,v;
- int main()
- {
- cin>>n>>k;
- for (int i=1; i<=n; i++)
- {
- cin>>a[i];
- s[i]=s[i-1]+a[i];
- dp[i][0]=s[i];
- }
- for (i=2; i<=n; i++)
- {
- int t=min(i-1,k);///最多多少乘号
- for (j=1;j<=t;j++)///遍历乘号个数
- for (v=2;v<=i;v++)///遍历乘号位置
- dp[i][j]=max(dp[i][j],dp[v-1][j-1]*(s[i]-s[v-1]));
- }
- cout<<dp[n][k];
- return 0;
- }
复制代码 |
|