标签:io os sp for on 问题 amp as tt
#include<iostream> using namespace std; int bottom_up_cut_rod(int p[],int n,int &pos) { int *r=new int[n+1]; int *s=new int[n+1]; for(int i=0;i<=n;++i) s[i]=0; for(int i=0;i<=n;++i) r[i]=0; for(int j=1;j<=n;++j) { int q=-1; for(int i=1;i<=j;++i) { //q=q>p[i]+r[j-i]?q:p[i]+r[j-i]; if(q<p[i]+r[j-i]) { q=p[i]+r[j-i]; s[j]=i; } } r[j]=q; } pos=s[n]; return r[n]; } int main() { const int size=10 ; int p[11]={0,1,5,8,9,10,17,17,20,24,30}; int pos; int sum=bottom_up_cut_rod(p,size,pos); cout<<sum<<endl; cout<<pos<<endl; system("pause"); return 0; }
标签:io os sp for on 问题 amp as tt
原文地址:http://blog.csdn.net/qq_22335577/article/details/41948259