Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int a[5] = {1, 5, 10, 25, 50};
- long long m[5][30001];
- int n, i, j;
- for(i=0; i<5; i++)
- m[i][0] = 1;
- for(i=0; i<30001; i++)
- m[0][i] = 1;
- for(i=1; i<5; i++)
- {
- for(j=1; j<30001; j++)
- {
- if(j >= a[i])
- m[i][j] = m[i-1][j] + m[i][j-a[i]];
- else
- m[i][j] = m[i-1][j];
- }
- }
- while(scanf("%d\n", &n) == 1)
- {
- if(m[4][n] == 1)
- printf("There is only 1 way to produce %d cents change.\n", n);
- else
- printf("There are %lld ways to produce %d cents change.\n", m[4][n], n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment