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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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