Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <climits>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char const *argv[])
  9. {
  10. int size = 10*10*10*10*10*10 + 1;
  11. vector<int> optimos(size + 1, INT_MAX);
  12. optimos[1] = 1;
  13. for(int i = 0; i < binarios.size(); i++){
  14. int binario = binarios[i];
  15. for(int j = binario ; j + binario < size; j++){
  16. optimos[binario + j] = min(optimos[binario+j], 1 + optimos[j]);
  17. }
  18. }
  19.  
  20. int n; cin >> n;
  21. string res = "";
  22. int pasos_original = optimos[n];
  23. while(n > 0){
  24. int pasos = optimos[n];
  25. for(int i = 0; binarios[i] < n; i++){
  26. int binario = binarios[i];
  27. if(optimos[n - binario] == pasos - 1){
  28. n = n - binario;
  29. res += to_string(binario) + " ";
  30. }
  31. }
  32. }
  33. cout << pasos_original << endl;
  34. cout << res << endl;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement