AlbertMourato

Untitled

Nov 26th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. using namespace std;
  4. int main(){
  5. int moedas[] ={0, 1, 5, 10, 25, 50};
  6. int n;
  7. cin>>n;
  8. int matriz[5][n+1];
  9. for(int i = 0; i<=n;i++){
  10. matriz[1][i] = 1;
  11. }
  12. for(int i = 0; i<=5;i++){
  13. matriz[i][1] = 1;
  14. matriz[i][0] = 1;
  15. }
  16. for(int i = 1; i<=5;i++){
  17. for(int j = 0; j<=n;j++){
  18. if(moedas[i]>j){
  19. matriz[i][j] = matriz[i-1][j];
  20. }else{
  21. matriz[i][j] = matriz[i-1][j]+matriz[i][j-moedas[i]];
  22. }
  23. }
  24. }
  25. cout<<matriz[5][n];
  26. }
Advertisement
Add Comment
Please, Sign In to add comment