-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10003.cpp
More file actions
45 lines (39 loc) · 687 Bytes
/
10003.cpp
File metadata and controls
45 lines (39 loc) · 687 Bytes
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
39
40
41
42
43
44
45
#include<stdio.h>
#define inf 99999999
#define min(a,b) (a<b ?a:b)
#define si 55
int dp[si][si],a[si];
int rec(int x,int y)
{
if(y-x==1)
return 0;
int &ret=dp[x][y];
if(ret!=-1)
return ret;
int cst,mn=inf,i;
for(i=x+1;i<y;i++)
{
cst=rec(x,i)+rec(i,y)+a[y]-a[x];
mn=min(cst,mn);
}
return ret=mn;
}
int main()
{
int l,n,i,j;
while(~scanf("%d",&l)&&l)
{
scanf("%d",&n);
for(i=0;i<=n+1;i++)
{
for(j=0;j<=n+1;j++)
dp[i][j]=-1;
}
a[0]=0;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
a[n+1]=l;
printf("The minimum cutting is %d.\n",rec(0,n+1));
}
return 0;
}