Advertisement
deushiro

Untitled

Nov 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11. typedef long long ll;
  12.  
  13. int counter = 0;
  14. int finder = -41;
  15. vector<char> ans;
  16. void solve(int n, int counter){
  17.     if(n == 0){
  18.         if(counter == finder){
  19.             for(int i = 0; i < ans.size(); ++i){
  20.                 cout << ans[i] << " ";
  21.         }
  22.            
  23.         }
  24.     }else{
  25.     ans.push_back('+');
  26.     solve(n - 1, counter + n);
  27.     if(ans.size() > 0)ans.pop_back();
  28.     ans.push_back('-');
  29.     solve(n - 1, counter - n);
  30.     if(ans.size() > 0)ans.pop_back();
  31.     }
  32. }
  33.  
  34. int main() {
  35.     ios_base::sync_with_stdio(false);
  36.     cin.tie(0);
  37.     cout.tie(0);
  38.     solve(9, 0);
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement