Find minimum number of coins that make a given value | m is size of coins array ( number of different coins ) ; base case ; Initialize result ; Try every coin that has smaller value than V ; Check for INT_MAX to avoid overflow and see if result can minimized ; Driver Code
< ? php function minCoins ( $ coins , $ m , $ V ) { if ( $ V == 0 ) return 0 ; $ res = PHP_INT_MAX ; for ( $ i = 0 ; $ i < $ m ; $ i ++ ) { if ( $ coins [ $ i ] <= $ V ) { $ sub_res = minCoins ( $ coins , $ m , $ V - $ coins [ $ i ] ) ; if ( $ sub_res != PHP_INT_MAX && $ sub_res + 1 < $ res ) $ res = $ sub_res + 1 ; } } return $ res ; } $ coins = array ( 9 , 6 , 5 , 1 ) ; $ m = sizeof ( $ coins ) ; $ V = 11 ; echo " Minimum ▁ coins ▁ required ▁ is ▁ " , minCoins ( $ coins , $ m , $ V ) ; ? >