Advertisement
DiaxPlayer

Untitled

Feb 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. class combSet
  2. {
  3. public:
  4.     void add(int a)
  5.     {
  6.         tab.push_back(a);
  7.     }
  8.     int calculate()
  9.     {
  10.         go_step(0, -1);
  11.         return get_max();
  12.     }
  13. private:
  14.     void go_step(int sum, int i)
  15.     {
  16.         if ( i >= (int)tab.size()-1)
  17.         {
  18.             sums.push_back(sum);
  19.             std::cout << "sum= "<< sum << std::endl;
  20.             return;
  21.         }
  22.         go_step(sum + tab[i+1], i+1);
  23.         if (i < (int)tab.size()-2)
  24.             go_step(sum + tab[i+2], i+2);
  25.         else
  26.             go_step(sum, i+2);
  27.     }
  28.     int get_max()
  29.     {
  30.         int xd =  tab[0];//*std::max_element(tab.begin(), tab.end());
  31.         for (auto i = 0u; i < tab.size(); i++)
  32.         {
  33.             std::cout << "vec-" << tab[i] << std::endl;
  34.             if (tab[i]>xd)
  35.             {
  36.                 xd = tab[i];
  37.             }
  38.         }
  39.         std::cout << "xd = " << xd << std::endl;
  40.         if (tab.size() == 1)
  41.         return 0;
  42.         return xd;
  43.     }
  44.     std::vector<int> tab;
  45.     std::vector<int> sums;a
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement