bhupixb

Minimum coins for change dp for n > 1e6

Jul 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. const int N = 255;
  4. typedef long long int ll;
  5. long long n = 5, ans = 0, cnt;
  6. long long v[5] = {4, 2, 8, 10, 100};
  7. void coin(long long sum, long long len){
  8.  
  9. if(sum == 0){
  10. ans = max(ans, len);//ans = min(ans, len);
  11. return ;
  12. }
  13.  
  14. for(int i = 0; i < n; i++){
  15. if(sum >= v[i])
  16. coin(sum%v[i],1LL *(sum/v[i] + len));
  17. else return;
  18. }
  19.  
  20. }
  21. int main(){
  22.  
  23. ll sum;
  24. cin >> sum ;
  25. n = 5;
  26.  
  27. coin(sum, 0);
  28. if(ans != INT_MAX)
  29. cout << ans;
  30. else
  31. cout << -1;
  32. }
Add Comment
Please, Sign In to add comment