dfs
View Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define maxn 20 int n; int f[maxn]; int g[maxn]; void input() { for (int i = 0; i < n; i++) scanf("%d", &f[i]); } void output() { for (int i = 0; i < 5; i++) printf("%d ", g[i]); printf("%d\n", g[5]); } void dfs(int step, int p) { if (step == 6) { output(); return; } for (int i = p; i < n - 5 + step; i++) { g[step] = f[i]; dfs(step + 1, i + 1); } } int main() { // freopen("t.txt", "r", stdin); bool first = true; while (scanf("%d", &n), n) { if (first) first = false; else putchar('\n'); input(); dfs(0, 0); } return 0; }