Maximum value with the choice of either dividing or considering as it is | Java program for maximize result when we have choice to divide or consider as it is . ; function for calculating max possible result ; Compute remaining values in bottom up manner . ; Driver Code
import java . io . * ; class GFG { static int maxDP ( int n ) { int res [ ] = new int [ n + 1 ] ; res [ 0 ] = 0 ; res [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ; return res [ n ] ; } public static void main ( String [ ] args ) { int n = 60 ; System . out . println ( " MaxSum ▁ = ▁ " + maxDP ( n ) ) ; } }