Count the number of ways to divide N in k groups incrementally | Function to count the number of ways to divide the number N in groups such that each group has K number of elements ; Base Case ; If N is divides completely into less than k groups ; Put all possible values greater equal to prev ; Function to count the number of ways to divide the number N ; Driver Code
def calculate ( pos , prev , left , k ) : NEW_LINE INDENT if ( pos == k ) : NEW_LINE INDENT if ( left == 0 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT if ( left == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT answer = 0 ; NEW_LINE for i in range ( prev , left + 1 ) : NEW_LINE INDENT answer += calculate ( pos + 1 , i , left - i , k ) ; NEW_LINE DEDENT return answer ; NEW_LINE DEDENT def countWaystoDivide ( n , k ) : NEW_LINE INDENT return calculate ( 0 , 1 , n , k ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 8 ; NEW_LINE K = 4 ; NEW_LINE print ( countWaystoDivide ( N , K ) ) ; NEW_LINE DEDENT