//此题一看便是简单的回溯题用DFS+回溯便可以做出来了、 #include <iostream> #define MAXN 20 using namespace std; int _m[MAXN]; int out[6]; int index; void DFS(int time); int n; int main() { //freopen("acm.acm","r",stdin); int i; while(cin>>n,n) { for(i = 0; i < n; ++ i) { cin>>_m[i]; } index = 0; DFS(0); cout<<endl; } } void DFS(int time) { if(index == 6) { int i; for(i = 0; i < index; ++ i) { cout<<out[i]<<" "; } cout<<endl; return; } if(n - time + index < 6) { return; } out[index ++] = _m[time]; DFS(time+1); -- index; DFS(time+1); }