The maximum product dynamic programming (integer division) --- integer division

The largest product division of integers

Subject description:

  To an integer, integer divided, and the divided number is the integer required to obtain maximum product divided.

Analysis of ideas:

  Dynamic programming, with DP [i] represents the maximum integer i divided product.

Code:

public int integerBreak(int n){
    int []dp=new int [n+1];
    dp[1]=1;
    for(int i=2;i<=n;i++){
        for(int j=1;j<=i-1;j++){
            dp[i]=Math.max(dp[i],Math.max(j*dp[i-j],j*(i-j)));
        }
    }
    return dp[n];
}

Guess you like

Origin www.cnblogs.com/yjxyy/p/11116476.html