#include<vector>
using namespace std;
#define INF 1000000
int MinCoin(vector<int>coin,int N)
{
vector<int>DP(++N,INF);
int i,j;
DP[0]=0;
for(i=0;i<N;i++)
for(j=0;j<coin.size();j++)
if(coin[j]<=i && DP[i-coin[j]]+1<DP[i])
DP[i]=DP[i-coin[j]]+1;
return DP[N-1];
}
int main()
{
int i,n,val;
vector<int>coin;
while(scanf("%d",&n)==1)
{
coin.clear();
for(i=0;i<n;i++)
{
scanf("%d",&val); coin.push_back(val);
}
scanf("%d",&val);
val=MinCoin(coin,val);
cout<<"Minimum Coin:"<<val<<endl;
}
return 0;
}
/*
Input:
3 No. Of Coins
1 3 5 List Of Coins
11 Minimum Coin 3 for 11 (5 5 1)
3
1 3 5
8 Minimum Coin 2 for 8 (5 3)
*/
No comments:
Post a Comment