human
Number of ways to write N as a sum of K non | Function to count the number of ways to write N as sum of k non - negative integers.
Initialise dp [ ] [ ] array.
Only 1 way to choose the value with sum K.
Initialise sum.
Count the ways from previous states.
Update the sum.
Return the final count of ways.
Driver Code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to number of ways to write N as a sum of K non and the other steps required.
 def countWays ( n , m ) :
	dp = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
	for i in range ( n + 1 ) :
		dp [ 1 ] [ i ] = 1
	sum = 0
	for i in range ( 2 , m + 1 ) :
		for j in range ( n + 1 ) :
			sum = 0
			for k in range ( j + 1 ) :
				sum += dp [ i - 1 ] [ k ]
			dp [ i ] [ j ] = sum
	return dp [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
	N = 2
	K = 3
	print ( countWays ( N , K ) )