Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define inf 100000
  4. int main() {
  5. int coinnumbers,a;
  6. vector <int> coins;
  7. int money ;
  8. scanf("%d",&money);
  9. scanf("%d",&coinnumbers);
  10. int mat[coinnumbers][money+1];
  11. for ( int i = 0 ; i < coinnumbers ; i++) {
  12. scanf("%d",&a);
  13. coins.push_back(a);
  14. }
  15. for ( int i = 0 ; i < coinnumbers ; i++) {
  16. for ( int j = 0 ; j < money+1 ; j++) {
  17. mat[i][j] = inf ;
  18. }
  19. }
  20.  
  21.  
  22. for ( int i = 0 ; i < coinnumbers ; i++) {
  23. mat[i][0] = 0 ;
  24. }
  25. for ( int i = 0 ; i < coinnumbers ; i++) {
  26. for ( int j = 0 ; j < money+1 ; j++) {
  27. if ( j - coins[i] < 0) {
  28. if ( i - 1 >= 0 ) mat[i][j] = mat[i-1][j];
  29. }
  30. else {
  31. if ( i - 1 >= 0 ) mat[i][j] = min(mat[i-1][j],mat[i][j-coins[i]]+1);
  32. else mat[i][j] = mat[i][j-coins[i]]+1;
  33. }
  34. }
  35. }
  36. for ( int i = 0 ; i < coinnumbers ; i++) {
  37. for ( int j = 0 ; j < money+1 ; j++) {
  38. cout << mat[i][j] << " ";
  39. }
  40. cout << endl;
  41. }
  42. return 0 ;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement