题解 | #剪绳子#
剪绳子
https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8
class Solution { public: int cutRope(int number) { if(number<=4) { return number; } vector<int> ans(number,0); ans[0]=1; ans[1]=2; ans[2]=3; ans[3]=4; for(int i=4;i<number;i++) { for(int j=1;j*2<i;j++) { ans[i]=max(ans[i],ans[j]*ans[i-j-1]); } } return ans[number-1]; } };