POJ 2245
按字典序选一个六组合。简单DFS
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int se[20]; int ans[20]; void dfs(int ps,int position,int k){ if(position>k){ if(ps==6){ printf("%d",ans[1]); for(int i=2;i<=6;i++) printf(" %d",ans[i]); printf("\n"); } return ; } ans[ps+1]=se[position]; dfs(ps+1,position+1,k); dfs(ps,position+1,k); } int main(){ int k; while(scanf("%d",&k),k){ for(int i=1;i<=k;i++) scanf("%d",&se[i]); dfs(0,1,k); printf("\n"); } return 0; }