Count number of ways to partition a set into k subsets | Returns count of different partitions of n elements in k subsets ; Base cases ; S ( n + 1 , k ) = k * S ( n , k ) + S ( n , k - 1 ) ; Driver Code
def countP ( n , k ) : NEW_LINE INDENT if ( n == 0 or k == 0 or k > n ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( k == 1 or k == n ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return ( k * countP ( n - 1 , k ) + countP ( n - 1 , k - 1 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( countP ( 3 , 2 ) ) NEW_LINE DEDENT