Find number of solutions of a linear equation of n variables | Returns count of solutions for given rhs and coefficients coeff [ 0. . n - 1 ] ; Create and initialize a table to store results of subproblems ; Fill table in bottom up manner ; Driver Code
< ? php function countSol ( $ coeff , $ n , $ rhs ) { $ dp = str_repeat ( " \0" , 256 ) ; $ dp [ 0 ] = 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) for ( $ j = $ coeff [ $ i ] ; $ j <= $ rhs ; $ j ++ ) $ dp [ $ j ] = $ dp [ $ j ] + ( $ dp [ $ j - $ coeff [ $ i ] ] ) ; return $ dp [ $ rhs ] ; } $ coeff = array ( 2 , 2 , 5 ) ; $ rhs = 4 ; $ n = sizeof ( $ coeff ) / sizeof ( $ coeff [ 0 ] ) ; echo countSol ( $ coeff , $ n , $ rhs ) ; ? >