human
Construct the largest number whose sum of cost of digits is K | Function to find the maximum number among the two numbers S and T.
If "0" exists in the string S.
If "0" exists in the string T.
Else return the maximum number formed.
Recursive function to find maximum number formed such that the sum of cost of digits of formed number is K.
Base Case.
Return the stored state.
Including the digit ( idx + 1 ).
Excluding the digit ( idx + 1 ).
Store the result and return.
Function to find the maximum number formed such that the sum of the cost digits in the formed number is K.
Stores all Dp - states.
Recursive Call.
Return the result.
Driver Code"
Solution in Python:

Write me a code to construct the largest number whose sum of cost of digits is K and the other steps required?
assistant
#Here is code to construct the largest number whose sum of cost of digits is K and the other steps required.
 def getMaximum ( S , T ) :
	if ( S . count ( "0" ) > 0 ) :
		return T ;
	if ( T . count ( "0" ) > 0 ) :
		return S ;
	return S if len ( S ) > len ( T ) else T ;
def recursion ( arr , idx , N , K , dp ) :
	if ( K == 0 ) :
		return " " ;
	if ( K < 0 or idx == N ) :
		return "0" ;
	if ( dp [ idx ] [ K ] != " - 1" ) :
		return dp [ idx ] [ K ] ;
	include = str ( idx + 1 ) + recursion ( arr , 0 , N , K - arr [ idx ] , dp ) ;
	exclude = recursion ( arr , idx + 1 , N , K , dp ) ;
	dp [ idx ] [ K ] = getMaximum ( include , exclude )
	return ( dp [ idx ] [ K ] )
def largestNumber ( arr , N , K ) :
	dp = [ [ " - 1" for i in range ( K + 1 ) ] for i in range ( N + 1 ) ]
	ans = recursion ( arr , 0 , N , K , dp ) ;
	return "0" if ans == " " else ans ;
arr = [ 3 , 12 , 9 , 5 , 3 , 4 , 6 , 5 , 10 ] ;
K = 14 ;
N = len ( arr ) ;
print ( largestNumber ( arr , N , K ) ) ;