File size: 825 Bytes
c4b0eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/*
>>~~ UVa Online Judge ACM Problem Solution ~~<<
ID: 10003
Name: Cutting Sticks
Problem: https://onlinejudge.org/external/100/10003.pdf
Language: C++
Author: Arash Shakery
Email: [email protected]
*/
#include <stdio.h>
#include <iostream>
using namespace std;
short int c[55],DP[55][55];
int main(){
int ll;
register int l,i,e,k,n,m;
while(scanf("%d",&ll)==1 && ll){
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",c+i);
c[n+1]=ll;
for(l=2; l<=n+1; l++)
for(i=0; i<=n+1-l; i++){
e=i+l;
short int &m=DP[i][e]=32767;
for(k=i+1; k<e; k++)
m=min(m,(short)(DP[i][k]+DP[k][e]+c[e]-c[i]));
}
printf("The minimum cutting is %d.\n",DP[0][n+1]);
}
} |