DYNAMIC PROGRAMMING

Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many coins of one type as we want), or report that it's not possible to select coins in such a way that they sum up to S.

I wrote the code below to solve this problem using dynamic programming but its not working..please help.

#include<iostream>
#include<stdio.h>
int main()
{
int s=18;
int n=3;
int v[n];
v[0]=1;
v[1]=3;
v[2]=5;
int min[s];
min[0]=0;
for(int i=1;i<s;i++)
{
min[i]=99999;
}
for(int i=1;i<s;i++)
{
for(int j=0;j<n;j++)
{
int vj=v[j];
if(vj<=i && min[i]-vj+1<min[i])
{
min[i]=min[i]-vj;
}

}
break;
}
printf("%d\n",min[1]);
return 0;
}
Arrays must be declared with a constant size. In your code you are assigning non-constant variables to the array sizes, which is illegal.
Topic archived. No new replies allowed.