Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python | Dynamic Programming Algorithm Implementation Given coins of denominations (value) 1 = v 1 2n, we wish to make change for an amount A

Python | Dynamic Programming Algorithm Implementation

Given coins of denominations (value) 1 = v1 2n, we wish to make change for an amount A using as few coins as possible. Assume that vi s and A are integers. Since v1= 1 there will always be a solution.

Formally, an algorithm for this problem should take as input:

An array V where V[i] is the value of the coin of the i th denomination.

A value A which is the amount of change we are asked to make

The algorithm should return an array C where C[i] is the number of coins of value V[i] to return as change and m the minimum number of coins it took. You must return exact change so:

image text in transcribed

The objective is to minimize the number of coins returned or:

image text in transcribed

The program should read input from a file named amount.txt. The file contains lists of denominations (V) followed on the next line by the amount A:

image text in transcribed

In the above example the first line contains the denominations V=(1, 2, 5) and the next line contains the amount A = 10 for which we need change. There are three different denomination sets and amounts in the above example. A denomination set will be on a single line and will always start with the 1 coin.

The results should be written to a file named change.txt and should contain the denomination set, the amount A, the change result array and the minimum number of coins used.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Image Databases Towards Advanced Image Retrieval

Authors: Yihong Gong

1st Edition

1461375037, 978-1461375036

More Books

Students also viewed these Databases questions