DFS+记忆化搜索
int f[100];
class Solution {
public:
int ans = 1;
void dfs(int x,int mult){
//cout<<x<<" "<<mult<<endl;
if(x<0) return;
if(mult<=f[x]) return;//剪枝
f[x] = mult;
if(x == 0){
ans = max(ans,mult);
return ;
}
for(int i=2;i<=x;i++){
dfs(x-i, mult*i);
}
}
int maxProductAfterCutting(int length) {
if(length == 2) return 1;
dfs(length,1);
return ans;
}
};