-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva357.cpp
57 lines (47 loc) · 1.11 KB
/
uva357.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
vector<int> coin;
long long int dp(int change)
{
int i,j;
vector<vector<long long int>> ara;
ara.resize(6,vector<long long int>(change+1,1));
ara[0].assign(change+1,0);
for(i=1; i<=5; i++)
{
for(j=1; j<=change; j++)
{
if(j<coin[i-1])
ara[i][j]=ara[i-1][j];
else
ara[i][j]=ara[i-1][j]+ara[i][j-coin[i-1]];
}
}
/*for(i=1; i<=5; i++)
{
for(j=0; j<=change; j++)
{
cout<<ara[i][j]<<" ";
}
cout<<endl;
}*/
return ara[5][change];
}
int main()
{
long long int i,j,change;
int ara[]= {1,5,10,25,50};
coin.assign(ara,ara+5);
int test;
while (1==scanf("%d",&change))
{
long long int n=dp(change);
if(n>1)
printf("There are %lld ways to produce %d cents change.\n",n,change);
else
{
printf("There is only 1 way to produce %d cents change.\n",change);
}
}
//return main();
}