#include<bits/stdc++.h>
using namespace std;
int coin_need(vector<int>v, int tk)
{
int i, j, t[tk+1];
t[0] = 0;
for(i=1;i<=tk;i++)
{
int minimum = 1000000;
for(j=1;j<v.size();j++)
{
if(v[j] <= i)
{
minimum = min(minimum, 1 + t[i-v[j]]);
}
}
t[i] = minimum;
}
return t[tk];
}
int main()
{
int n, i, tk;
cout << "Enter Coin Number :: ";
cin >> n;
vector<int>v(n+1);
cout << "Enter Coin Value :: ";
for(i=1;i<=n;i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
cout << "Enter Total Amount :: ";
cin >> tk;
cout << "Minimum Coin Required :: " << coin_need(v, tk) << "\n";
return 0;
}
using namespace std;
int coin_need(vector<int>v, int tk)
{
int i, j, t[tk+1];
t[0] = 0;
for(i=1;i<=tk;i++)
{
int minimum = 1000000;
for(j=1;j<v.size();j++)
{
if(v[j] <= i)
{
minimum = min(minimum, 1 + t[i-v[j]]);
}
}
t[i] = minimum;
}
return t[tk];
}
int main()
{
int n, i, tk;
cout << "Enter Coin Number :: ";
cin >> n;
vector<int>v(n+1);
cout << "Enter Coin Value :: ";
for(i=1;i<=n;i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
cout << "Enter Total Amount :: ";
cin >> tk;
cout << "Minimum Coin Required :: " << coin_need(v, tk) << "\n";
return 0;
}
Comments
Post a Comment