UVA 1625 Color Length

来源:互联网 发布:网络协议实践加密技术 编辑:程序博客网 时间:2024/04/30 17:10
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm> #include<cmath>#include<vector>using namespace std;const int maxn=1000+5;int L,N,C[maxn],d[maxn][maxn];int dp(int left,int right){int& ans=d[left][right];if(ans!=-1) return ans;ans=(1<<30);int ok=0;       //标记改段是否可以被锯掉 for(int i=0;i<N;i++)if(left<C[i]&&right>C[i]){ans=min(ans,dp(left,C[i])+dp(C[i],right)+right-left);ok=1; }return ok?ans:ans=0;}int main(){while(cin>>L&&L){cin>>N;for(int i=0;i<N;i++) cin>>C[i];memset(d,-1,sizeof(d));printf("The minimum cutting is %d.\n",dp(0,L));}return 0;} 

0 0
原创粉丝点击