Coin change program

Assignment Help JAVA Programming
Reference no: EM13165383

coin change program. Make change using fewest number of coins. I'm attempting dynamic programming and i may be misunderstanding the algorithm. When i compile, the debug assertion fails and i receive the expression: vector subscript out of range.

the algorithm i'm trying to follow is:

Input Parameters: denom,A
Output Parameter: C

dynamic_coin_change1(denom,A, C) {
n = denom.last
for j = 0 to A
C[n][j] = j
for i = n ? 1 downto 1
for j = 0 to A
if (denom[i] > j || C[i + 1][j] < 1 + C[i][j ? denom[i]])
C[i][j] = C[i + 1][j]
else
C[i][j] = 1 + C[i][j ? denom[i]]
}

My code so far is:

    #include <iostream>
    #include <vector>

    int main()
    {
        vector<int> denom{3,2,8,10};
        int n = denom.size();
        int sum = 57;
        int j = 0;
        int i = 0;
        typedef vector<vector<int>> matrix;
        matrix solVec(n,vector<int>(sum));

        for(i = n-1;i >= 1; i--)
          {
              for(j = 0; j <= sum; j++)
                {
                    if(denom[i]>j || solVec[i+1][j] < 1 + solVec[i][j - denom[i]])
                        solVec[i][j] = solVec[i+1][j];
                    else
                        solVec[i][j] = 1 + solVec[i][j - denom[i]];
                {
          }
      cout<<solVec[i][j];
      system("pause");
      return 0;

 

 

Reference no: EM13165383

Questions Cloud

Store a list of student info : Store a list of student info, (id number, First name and Last name) using a link list. The ID is the key field. The program should implement a linked list using arrays.The program should process the following operations
Singly linked list : Singly Linked List (SLL)Introduce a SLL class with the following functions. Please also introduce a main function that will invoke and verify whether the functions are implemented correctly
Compare the tax advantages of debt versus equity : Compare the tax advantages of debt versus equity capital formation of the corporation for the client and debt or equity for capital formation of thenew corporation, based on your research
Write net ionic equations for the reactions : Write net ionic equations for the reactions that take place when aqueous solutions of the following substances are mixed.
Coin change program : coin change program. Make change using fewest number of coins. I'm attempting dynamic programming and i may be misunderstanding the algorithm
A current implementation of a particular multicore : A current implementation of a particular multicore processor has a 64KB Level one cache for each core, 256KB Level two, and 6MB for level three.
Compute the equivalent weight of the unknown weak acid : Calculate the equivalent weight of the unknown weak acid (g/eq). Calculate the molecular weight of the acid described in Question 1 (g/mol).
What is last years return on investment : What is last year's return on investment and what is the margin related to this year's investment opportunity
What will be the temperature of the sample : A 3.00-liter sample of gas is at 417 Kelvin and 0.65 atmosphere. If the volume is decreased to 1.50 liters and the pressure of the gas is increased to 1.95 atmospheres, what will be the temperature of the sample?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write java program to print price of table-furniture company

Write down the Java program for furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate the price of table produced with chosen wood.

  Write a recursive method to produce a pattern

Write a recursive method to produce a pattern of n lines of asterisks.

  Eclipse or netbeans environments

As recommendation, you can try to use Eclipse or NetBeans environments that are used also for other courses as: Introduction in Java programming and Intermediate programming.

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

  Write a method in java that uses a switch statement

Write a method in JAVA that uses a switch statement and takes a person's age using an integer parameter , then checks if the age is valid (0-110), and then RETURNS a string based on the age

  Have to implement a search algorithm

Suppose you have to implement a search algorithm in a high programming language such as Java or C++. You are given a linked list that is not sorted and it's rather small, in the order of a few dozen elements.

  Comparator that compares point objects by their distance

write a comparator that compares point objects by their distance from the origin of (0,0). points that are closer to the origin are considered to come before those which are further from the origin

  Write a program to register students for a college

Students have names, addresses and courses. Implement the interface class RegisterStudent. RegisterStudent has one method, public boolean register, which returns the boolean value of true or false if the student is successfully registered for the ..

  Graphicsframe class

This program makes use of the GraphicsFrame class and the Drawable interface. Your missions is to create the class Airplane. Each Airplane object should store the following information (fields): manufacturer modelNumber maximumSpeed // in knots maxim..

  Find the solution of all these java question

find the solution of all these java question

  Write complete java program to read from keyboard

Write complete Java program to read, from keyboard, a student's first and last name and six grades. It will display on screen last name then first letter of first name with a period.

  Create web application uses visual web java server

Create the Web application which uses Visual Web Java Server Faces framework and either Apache Tomcat or Glassfish as the server.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd