UVA 10003 Cutting sticks

<pre name="code" class="cpp">#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define maxn 100000

int p[55],dp[55][55];

int main()
{
    int L,n;
    while(cin>>L&&L)
    {
        memset(dp,0,sizeof(dp));
        cin>>n;
        for(int i=1; i<=n; i++)
            cin>>p[i];
          p[0]=0,p[n+1]=L;
        for(int l=2; l<=n+1; l++)
            for(int i=0; i+l<=n+1; i++)
        {
             int  j=i+l;
             dp[i][j]=maxn;
            for(int k=i; k<j; k++)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+p[j]-p[i]);
        }
        cout<<"The minimum cutting is "<<dp[0][n+1]<<"."<<endl;
    }
}


 
 
 

你可能感兴趣的:(ACM,uva)