ZOJ1089(dfs)

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int a[22], b[22];
int n;
void print() {
    for(int i = 1; i <= 6; i++) {
        printf("%d%c", a[b[i]], (i == 6) ? '\n' : ' ');
    }
}
void dfs(int x, int st) {
    b[x] = st;
    if(x > 6) {
        print();
        return;
    }
    if(st > n)
        return;
    dfs(x+1, st+1);
    dfs(x, st+1);
}
int main() {
    int k = 0;
    while(scanf("%d", &n) && n) {
        k++;
        if(k != 1) {
            printf("\n");
        }
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
        }
        for(int i = 1; i <= 6; i++) {
            b[i] = i;
        }
        dfs(1, 1);
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章