Advertisement
Najmul_Kabir

36

Aug 25th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include<stdio.h>
  2. int arr[]={1,5,10,25,50};
  3. int n=5,$;
  4.  
  5. int coinChange();
  6.  
  7. int main()
  8. {
  9. while(scanf("%d",&$)!=EOF)
  10. {
  11. int answer=0;
  12. answer=coinChange();
  13. printf("%d\n",answer);
  14. }
  15. return 0;
  16. }
  17.  
  18. int coinChange()
  19. {
  20. int i,j,x,y;
  21. int TB[$+1][n];
  22.  
  23. for(i=0;i<n;i++)
  24. TB[0][i]=1;
  25.  
  26. for(i=1;i<=$;i++)
  27. for(j=0;j<n;j++)
  28. {
  29. if((i-arr[j])>=0)
  30. x=TB[i-arr[j]][j];
  31. else x=0;
  32.  
  33. if(j>=1)
  34. y=TB[i][j-1];
  35. else y=0;
  36.  
  37. TB[i][j]=x+y;
  38. }
  39.  
  40. return TB[$][n-1];
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement