Hi,

Please help me with this problem, im reading algorithms
i've seen a problem called "Coin Change"
the algorithm located here: http://www.algorithmist.com/index.php/Coin_Change

i have problem in implementation in C++, can anyone please help me with the base case.
I have no idea how to fill the array with base cases.

void coinBuild(void)
{
	for(int i = 0; i < MAX; i++)
	{
		for(int j = 0; j < 5; j++)
		{
			if(i == 0)
				dyna[i][j] = 1;
			else if(i <= 0)
				dyna[i][j] = 0;
			else if(i >= 1 && j <= 0)
				dyna[i][j] = 0;
			else 
				dyna[i][j] = dyna[i][j - 1] + dyna[i - coin[j]][j];
		}
	}
}

Since the solutions will not all have the same number of coins, I recommend you use a std::vector<std::vector<int> > . Can you enumerate an example input, the current output, and the expected output for us?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.