least number of coins to form a sum
C++
// A Dynamic Programming based C++ program to find minimum of coins
// to make a given change V
#include<bits/stdc++.h>
using namespace std;
// m is size of coins array (number of different coins)
int minCoins(int coins[], int m, int V)
{
// table[i] will be storing the minimum number of coins
// required for i value. So table[V] will have result
int table[V+1];
// Base case (If given value V is 0)
table[0] = 0;
// Initialize all table values as Infinite
for (int i=1; i<=V; i++)
table[i] = INT_MAX;
// Compute minimum coins required for all
// values from 1 to V
for (int i=1; i<=V; i++)
{
// Go through all coins smaller than i
for (int j=0; j<m; j++)
if (coins[j] <= i)
{
int sub_res = table[i-coins[j]];
if (sub_res != INT_MAX && sub_res + 1 < table[i])
table[i] = sub_res + 1;
}
}
return table[V];
}
// Driver program to test above function
int main()
{
int coins[] = {9, 6, 5, 1};
int m = sizeof(coins)/sizeof(coins[0]);
int V = 11;
cout << "Minimum coins required is "
<< minCoins(coins, m, V);
return 0;
}
Also in C++:
- Title
- c++ vector add element
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- clear console c++
- Category
- C++
- Title
- c++ initialize a vector
- Category
- C++
- Title
- c++ class template
- Category
- C++
- Title
- insertion c++
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- mkdir c++
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- howt o initialize 3d vector in c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- how to make sure the user inputs a int and not anything else c++
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- ceil in c++
- Category
- C++
- Title
- convert entire string to lowercase c++
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- c++ round to int
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- sqrt cpp
- Category
- C++
- Title
- recursive in c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- opperanf >> c++
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- pass by reference c++
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- c++ switch
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- c++ stream string into fiel
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- font awesome bootstrap cdn
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- if esle in c++
- Category
- C++
- Title
- sleep system function linux c++
- Category
- C++
- Title
- loop through words in string c++
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- how to concatinate two strings in c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- C++ sfinae
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- maximum subarray sum in c++
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- typeid to string c++
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- private and public in namespace cpp
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- c++ string
- Category
- C++
- Title
- convert int to binary string c++
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- glfw initialize in c++
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- syntax c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- factorial in c++
- Category
- C++
- Title
- heap sort
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- c++ std::copy to cout
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- find vector in c++
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- how to reverse a vector
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- fast input output in c++
- Category
- C++