Dynamic Programming | High | A DP based PHP program to find maximum tasks . Returns the maximum among the 2 numbers ; Returns the maximum among the 2 numbers ; Returns maximum amount of task that can be done till day n ; An array task_dp that stores the maximum task done ; If n = 0 , no solution exists ; If n = 1 , high effort task on that day will be the solution ; Fill the entire array determining which task to choose on day i ; Driver code
< ? php function max1 ( $ x , $ y ) { return ( $ x > $ y ? $ x : $ y ) ; } return ( $ x > $ y ? $ x : $ y ) ; } function maxTasks ( $ high , $ low , $ n ) { $ task_dp = array ( $ n + 1 ) ; $ task_dp [ 0 ] = 0 ; $ task_dp [ 1 ] = $ high [ 0 ] ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ task_dp [ $ i ] = max ( $ high [ $ i - 1 ] + $ task_dp [ $ i - 2 ] , $ low [ $ i - 1 ] + $ task_dp [ $ i - 1 ] ) ; return $ task_dp [ $ n ] ; } { $ n = 5 ; $ high = array ( 3 , 6 , 8 , 7 , 6 ) ; $ low = array ( 1 , 5 , 4 , 5 , 3 ) ; echo ( maxTasks ( $ high , $ low , $ n ) ) ; }