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 which will permit user to make selection

Write the Java Program which will permit the user to make selection. You will present user with two options to perform, then you will perform action selected by user.

  Java program to declares integer array

Write a complete Java program to declares integer array, intArray, and initialize it to {1, 2, 3, 4, 5, 6, 7}.

  Program that allows the user to enter the last names

Write a program that allows the user to enter the last names of 5 candidates in a college election and the votes received by each candidate. The program should then output each candidates name, the votes reveived by that candidate

  Java program ask user to enter 10-character telephone number

Write a Java program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The program should display the telephone number with any alphabetic characters

  Write java program to reads ten values from user

Write the java program which reads 10 values from user and store them in 1 daimantion array. your program will ask the user wich operation he wants to perform:

  Write java program to select pine for furniture company

Write down the Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany.

  Algorithm analysis with advanced data structures

Write a program to help the merchants devise a sequence of transmutations that would change silver into gold with the smallest possible total fee paid to the alchemists.

  User enter a series of numbers

Design a java program with a loop that lets the user enter a series of numbers. The user should enter - 99 to signal the end of the series. After all the numbers have been enter been entered, the program should display the largest and smallest number..

  Elliptic curve encryption

write a program to implement Elliptic Curve encryption/decryption and program will read parameters, plaintext and ciphertextfrom a file named "input.txt" (under the same directory).

  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!.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

  Writing a program that parses

The programming project involves writing a program that parses, using recursive descent, a GUI definition language defined in an input file and generates the GUI that it defines.

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