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;
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?
|