The cows have not only created their own government butthey have chosen to create their own money system. In their own rebellious way,they are curious about values of coinage. Traditionally, coins come in valueslike 1, 5, 10, 20 or 25, 50, and 100 units, sometimes with a 2 unit coin thrownin for good measure.
The cows want to know how many different ways it ispossible to dispense a certain amount of money using various coin systems. Forinstance, using a system of {1, 2, 5, 10, ...} it is possible to create 18units several different ways, including: 18x1, 9x2, 8x2+2x1, 3x5+2+1, and manyothers.
Write a program to compute how many ways to construct agiven amount of money using supplied coinage. It is guaranteed that the totalwill fit into both a signed long long (C/C++) and Int64 (Free Pascal).
PROGRAM NAME: money
INPUT FORMAT
The number of coins in the system is V (1 <= V <=25).
The amount money to construct is N (1 <= N <=10,000).
Line 1:Two integers, V and N
Lines 2..:V integers that represent the availablecoins (no particular number of integers per line)
SAMPLE INPUT (file money.in)
3 10
1 2 5
OUTPUT FORMAT
A single line containing the total number of ways toconstruct N money units using V coins.
SAMPLE OUTPUT (file money.out)
10
#include
#include
int cost[26]={0};
int method[26][10001]={0};
int main()
{
int v,n;
scanf("%d%d",&v,&n);
int i;
for(i=1;i<=v;i++)
{
scanf("%d",&cost[i]);
}
intj;
for(i=1;i<=n;i++)
{
for (j=1;j<=v;j++)
{
if(cost[j]>i)
{
continue;
}
if(i-cost[j]==0)
{
method[j][i]++;
}
elseif (i-cost[j]!=0)
{
intk;
for(k=0;k<=j;k++)
{
method[j][i]+=method[k][i-cost[j]];
}
}
}
}
int c=0;
for(i=1;i<=v;i++)
{
c+=method[i][n];
}
printf("%d\n",c);
return0;
}