比较水的dfs题目
code:
/*
ID: yueqiq
LANG: C++
TASK: zerosum
*/
#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <limits>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string.h>
#include <iostream>
#include <algorithm>
#define ls rt<<1
#define rs rt<<1|1
#define Si set<int>
#define LL long long
#define pb push_back
#define PS printf(" ")
#define Vi vector<int>
#define LN printf("\n")
#define SD(a) scanf("%d",&a)
#define PD(a) printf("%d",a)
#define SET(a,b) memset(a,b,sizeof(a))
#define FF(i,a) for(int i(0);i<(a);i++)
#define FD(i,a) for(int i(a);i>=(1);i--)
#define FOR(i,a,b) for(int i(a);i<=(b);i++)
#define FOD(i,a,b) for(int i(a);i>=(b);i--)
#define readf freopen("zerosum.in","r",stdin)
#define writef freopen("zerosum.out","w",stdout)
const double pi = acos(-1.0);
const int maxn = 50;
const int BigP = 99999999;
const int INF = 99999999;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
using namespace std;
int N;
char str[20];
void dfs(int k,int sum,int last){
if(k==N){
if(sum+last==0) cout<<str<<endl;
return ;
}
str[k*2-1]=' ';
dfs(k+1,sum,last>0?last*10+k+1:last*10-k-1);
str[k*2-1]='+';
dfs(k+1,sum+last,k+1);
str[k*2-1]='-';
dfs(k+1,sum+last,-k-1);
}
int main (){
readf;
writef;
SD(N);
FF(i,N) str[i*2]=char(i+'1');
dfs(1,0,1);
return 0;
}