uva 10003(区间dp)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=60;
const int nil=(1<<29);
int a[maxn];
int dp[maxn][maxn];
int main(){
int n;
int l;
while(scanf("%d",&l)&&l){
scanf("%d",&n);
memset(dp,0,sizeof(dp));
for (int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
a[0]=0;
a[n+1]=l;
for (int i=1;i<=n+1;i++){//枚举切点的长度,即从a[i],数组的长·
for (int j=0;j+i<=n+1;j++){//枚举从a[i]数组的哪个位置切
int p=i+j;
int minn=nil;
for (int k=j+1;k<p;k++){
int temp;
temp=dp[j][k]+dp[k][p]+a[p]-a[j];
if(temp<minn) minn=temp;
}
if(minn!=nil) dp[j][p]=minn;
}
}
printf("The minimum cutting is %d.\n",dp[0][n+1]);
}
return 0;
}