Number of ways to sum up a total of N from limited denominations | Function to find the number of ways to sum up a total of N from limited denominations ; Store the count of denominations ; Stores the final result ; As one of the denominations is rupee 1 , so we can reduce the computation by checking the equality for N - ( A * 1 ) = N - A ; Increment the count for number of ways ; Driver Code ; Given Denominations ; Function Call
def calculateWays ( arr1 , arr2 , N ) : NEW_LINE INDENT A = arr2 [ 0 ] NEW_LINE B = arr2 [ 1 ] NEW_LINE C = arr2 [ 2 ] NEW_LINE D = arr2 [ 3 ] NEW_LINE ans , b , c , d = 0 , 0 , 0 , 0 NEW_LINE while b <= B and b * 5 <= ( N ) : NEW_LINE INDENT c = 0 NEW_LINE while ( c <= C and b * 5 + c * 10 <= ( N ) ) : NEW_LINE INDENT d = 0 NEW_LINE while ( d <= D and b * 5 + c * 10 + d * 20 <= ( N ) ) : NEW_LINE INDENT if ( ( b * 5 ) + ( c * 10 ) + ( d * 20 ) >= ( N - A ) ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT d += 1 NEW_LINE DEDENT c += 1 NEW_LINE DEDENT b += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 123 NEW_LINE arr1 = [ 1 , 5 , 10 , 20 ] NEW_LINE arr2 = [ 6 , 4 , 3 , 5 ] NEW_LINE print ( calculateWays ( arr1 , arr2 , N ) ) NEW_LINE DEDENT