Advertisement
Guest User

Untitled

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