Number of ways to obtain each numbers in range [ 1 , b + c ] by adding any two numbers in range [ a , b ] and [ b , c ] | Python3 program to calculate the number of ways ; 2 is added because sometimes we will decrease the value out of bounds . ; Initialising the array with zeros . ; Printing the array ; Driver code
def CountWays ( a , b , c ) : NEW_LINE INDENT x = b + c + 2 ; NEW_LINE arr = [ 0 ] * x ; NEW_LINE for i in range ( 1 , b + 1 ) : NEW_LINE arr [ i + b ] = arr [ i + b ] + 1 ; NEW_LINE arr [ i + c + 1 ] = arr [ i + c + 1 ] - 1 ; NEW_LINE for i in range ( 1 , x - 1 ) : NEW_LINE arr [ i ] += arr [ i - 1 ] ; NEW_LINE print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 1 ; NEW_LINE b = 2 ; NEW_LINE c = 2 ; NEW_LINE CountWays ( a , b , c ) ; NEW_LINE DEDENT