Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class combSet
- {
- public:
- void add(int a)
- {
- tab.push_back(a);
- }
- int calculate()
- {
- go_step(0, -1);
- return get_max();
- }
- private:
- void go_step(int sum, int i)
- {
- if ( i >= (int)tab.size()-1)
- {
- sums.push_back(sum);
- std::cout << "sum= "<< sum << std::endl;
- return;
- }
- go_step(sum + tab[i+1], i+1);
- if (i < (int)tab.size()-2)
- go_step(sum + tab[i+2], i+2);
- else
- go_step(sum, i+2);
- }
- int get_max()
- {
- int xd = tab[0];//*std::max_element(tab.begin(), tab.end());
- for (auto i = 0u; i < tab.size(); i++)
- {
- std::cout << "vec-" << tab[i] << std::endl;
- if (tab[i]>xd)
- {
- xd = tab[i];
- }
- }
- std::cout << "xd = " << xd << std::endl;
- if (tab.size() == 1)
- return 0;
- return xd;
- }
- std::vector<int> tab;
- std::vector<int> sums;a
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement