-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path357.cpp
More file actions
executable file
·37 lines (31 loc) · 917 Bytes
/
357.cpp
File metadata and controls
executable file
·37 lines (31 loc) · 917 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int coin[5]={1,5,10,25,50};
long long dp[30009][5];
int main()
{
for(int i=0; i<30009; i++)
{
for(int j=0; j<5; j++ )
{
if(i==0)dp[i][j]=1;
else if (j==0)
{
if(i%coin[j]==0)dp[i][j]=1;
else dp[i][j]=0;
}
else if(coin[j]>i)
{
dp[i][j]=dp[i][j-1];
}
else dp[i][j]=dp[i-coin[j]][j]+dp[i][j-1];
}
}
int inp;
while(cin>>inp)
{
if(dp[inp][4]==1)
cout<<"There is only 1 way to produce "<<inp<<" cents change."<<endl;
else cout<<"There are "<<dp[inp][4]<<" ways to produce "<<inp<<" cents change."<<endl;
}
}