human
Can you provide a code to count ways to obtain given sum by repeated throws of a dice and the other steps required given the following:
Count ways to obtain given sum by repeated throws of a dice | Function to calculate the total number of ways to have sum N.
Base Case.
Return already stored result.
Recur for all 6 states.
Return the result.
Driver Code.
Given sum N.
Initialize the dp array.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to count ways to obtain given sum by repeated throws of a dice and the other steps required.
 def findWays ( N , dp ) :
	if ( N == 0 ) :
		return 1
	if ( dp [ N ] != - 1 ) :
		return dp [ N ]
	cnt = 0
	for i in range ( 1 , 7 ) :
		if ( N - i >= 0 ) :
			cnt = ( cnt + findWays ( N - i , dp ) )
	dp [ N ] = cnt
	return dp [ N ]
if __name__ == " _ _ main _ _ " :
	N = 4
	dp = [ - 1 ] * ( N + 1 )
	print ( findWays ( N , dp ) )