//(96ms, 312KB)
#include
void dfs(int left,int right,int N);
char ans[30];
int main(){111111111111111111111111111111111111111111111111111111111111111111111111
int N;
while(scanf("%d",&N)!=EOF){
dfs(0,0,N);
printf("\n");
}
return 0;
}
void dfs(int left,int right,int N){
if(left==right&&right==N){ans[right+left]='\0',printf("%s\n",ans);return;}
if(left<N)ans[left+right]='(',dfs(left+1,right,N);
if(right<left)ans[left+right]=')',dfs(left,right+1,N);
return;
}
解完題貼答案,很好奇您的心態。