Titulo
https://leetcode-cn.com/problems/jian-sheng-zi-lcof/
Ideas
f (n) = f (ni) * f (i) ... Cuando la
longitud es 1 2 3, no es necesario que participe en el cálculo
. El valor máximo de cada segmento se puede calcular de arriba a abajo.
class Solution {
public int cuttingRope(int length) {
if(length<2){
return 0;
}
if(length==2){
return 1;
}
if(length==3){
return 2;
}
int[] product = new int[length+1];
product[0] = 0;
product[1] = 1;
product[2] = 2;
product[3] = 3;
int max = 0;
for (int i = 4; i <= length; i++) {
max =0;
for (int j = 1; j <= i / 2; j++) {
int temp = product[j]*product[i-j];
if(max<temp){
max = temp;
}
product[i] = max;
}
}
return product[length];
}
}