题目描述—剪绳子—Java
public int maxProductAfterCutting(int n)
{
if(n < 2)
return 0;
if(n == 2)
return 1;
if(n == 3)
return 2;
int[] dp = new int[n + 1];
dp[1] = 1;
dp[2] = 2;
dp[3] = 3;
int max = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j < i; j++) {
int temp = dp[j] * dp[i - j];
if(max < temp)
max = temp;
}
if(i > 3)
dp[i] = max;
}
return dp[n];
}