Number of ways to sum up a total of N from limited denominations | Python3 program for the above approach ; 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 ; This will give the number of coins for all combinations of coins with value 1 and 5 ; L2 will sum the values of those indices of ways which is equal to ( N - ( c * 10 + d * 20 ) ) ; Return the final count ; Driver Code ; Given denominations ; Function call
ways = [ 0 for i in range ( 1010 ) ] ; NEW_LINE def calculateWays ( arr1 , arr2 , N ) : NEW_LINE INDENT A = arr2 [ 0 ] ; B = arr2 [ 1 ] ; NEW_LINE C = arr2 [ 2 ] ; D = arr2 [ 3 ] ; NEW_LINE ans = 0 ; NEW_LINE for b in range ( 0 , B + 1 ) : NEW_LINE INDENT if ( b * 5 > N ) : NEW_LINE INDENT break ; NEW_LINE DEDENT for a in range ( 0 , A + 1 ) : NEW_LINE INDENT if ( a + b * 5 > N ) : NEW_LINE INDENT break ; NEW_LINE DEDENT ways [ a + b * 5 ] += 5 ; NEW_LINE DEDENT DEDENT for c in range ( 0 , C ) : NEW_LINE INDENT if ( c * 10 > N ) : NEW_LINE INDENT break ; NEW_LINE DEDENT for d in range ( 0 , D ) : NEW_LINE INDENT if ( c * 10 + d * 20 > N ) : NEW_LINE INDENT break ; NEW_LINE DEDENT ans += ways [ N - c * 10 - d * 20 ] ; NEW_LINE DEDENT 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