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