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