普及组dp。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 2550
#define inf 2147483647
using namespace std;
int n,m,tab[maxn],dp[maxn];
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++) scanf("%d",&tab[i]);
for (int i=;i<=n;i++) tab[i]+=tab[i-];
for (int i=;i<=n;i++) dp[i]=inf;
for (int i=;i<=n;i++)
{
dp[i]=tab[i]+m;
for (int j=;j<=i-;j++)
dp[i]=min(dp[j]+tab[i-j]+m,dp[i]);
dp[i]+=m;
}
printf("%d\n",dp[n]-m);
return ;
}