题目
参考资料
https://leetcode.cn/problems/jian-sheng-zi-lcof/solution/jian-zhi-offer-14-i-jian-sheng-zi-huan-s-xopj/
https://leetcode.cn/problems/jian-sheng-zi-lcof/solution/jian-sheng-zi-by-leetcode-solution-xku9/
思路要点
还有数论的方法,暂停一下吧
代码
class Solution {
public:
int cuttingRope(int n) {
vector <int> dp(n+1);
int ans=0;
for(int i=2;i<=n;i++){
ans=0;
for(int j=1;j<i;j++){
ans=max(ans,max(dp[i-j]*j,(i-j)*j));
}
dp[i]=ans;
}
return dp[n];
}
};