算法1
动态规划 c++
C++ 代码
int maxProductAfterCutting(int length) {
int maxl[length+1];
memset(maxl,0,sizeof(maxl));
maxl[0] = 0;
maxl[1] = 1;
maxl[2] = 1;
maxl[3] = 2;
if(length>=4){
for(int i=4;i<=length;i++){
for(int j=1;j<=i/2;j++){
maxl[i]=max(maxl[i],max(j*(i-j),j*maxl[i-j]));
}
}
}
return maxl[length];
}