human
Check if it is possible to get given sum by taking one element from each row | Function that prints whether is it possible to make sum equal to K.
Base case.
Condition if we can make sum equal to current column by using above rows.
Iterate through current column and check whether we can make sum less than or equal to k.
Printing whether is it possible or not.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if it is possible to get given sum by taking one element from each row and the other steps required.
 def PossibleSum ( n , m , v , k ) :
	dp = [ [ 0 ] * ( k + 1 ) for i in range ( n + 1 ) ]
	dp [ 0 ] [ 0 ] = 1
	for i in range ( n ) :
		for j in range ( k + 1 ) :
			if dp [ i ] [ j ] == 1 :
				for d in range ( m ) :
					if ( j + v [ i ] [ d ] ) <= k :
						dp [ i + 1 ] [ j + v [ i ] [ d ] ] = 1
	if dp [ n ] [ k ] == 1 :
		print ( " YES " )
	else :
		print ( " NO " )
N = 2
M = 10
K = 5
arr = [ [ 4 , 0 , 15 , 3 , 2 , 20 , 10 , 1 , 5 , 4 ] , [ 4 , 0 , 10 , 3 , 2 , 25 , 4 , 1 , 5 , 4 ] ]
PossibleSum ( N , M , arr , K )