<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>动态规划-求绳子乘积最大值</title>
</head>
<body>
<script>
function isMax(intNumber)
{
if (intNumber<2)
{
return 0;
}
if (intNumber===2)
{
return 2;
}
if (intNumber===3)
{
return 3;
}
var arr=new Array(intNumber+1);
arr[0]=0;
arr[1]=1;
arr[2]=2;
arr[3]=3;
for (var i=4;i<=intNumber;i++)
{
var max=0;
for (var j=1;j<=i/2;j++){
var arrs=arr[j]*[i-j];
if (arrs>max)
{
max=arrs;/*更新max的值*/
}
arr[i]=max;/*保证每个子集都是最大值*/
}
}
return arr[intNumber];
}
console.log(isMax(4));
</script>
</body>
</html>
测试: 4 4;
6 9;