Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <map>
- #include <set>
- using namespace std;
- typedef long long ll;
- int counter = 0;
- int finder = -41;
- vector<char> ans;
- void solve(int n, int counter){
- if(n == 0){
- if(counter == finder){
- for(int i = 0; i < ans.size(); ++i){
- cout << ans[i] << " ";
- }
- }
- }else{
- ans.push_back('+');
- solve(n - 1, counter + n);
- if(ans.size() > 0)ans.pop_back();
- ans.push_back('-');
- solve(n - 1, counter - n);
- if(ans.size() > 0)ans.pop_back();
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- solve(9, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement