DFS练习。
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int SIZE = 51;
int save[SIZE], b[SIZE];
int ans, n;
void print()
{
for(int i = 1; i <= 6; i++)
{
printf(i!=6?"%d ":"%d\n", save[i]);
}
return ;
}
void dfs(int d)
{
if(ans == 6)
{
print();
return;
}
if(d > n) return ;
save[++ans] = b[d];
dfs(d+1);
--ans;
dfs(d+1);
}
int main()
{
int first = 0;
while(scanf("%d", &n), n)
{
if(first) printf("\n");
first = 1;
ans = 0;
memset(save, 0, sizeof(save));
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
dfs(1);
}
return 0;
}
#include <stdlib.h>
#include <string.h>
using namespace std;
const int SIZE = 51;
int save[SIZE], b[SIZE];
int ans, n;
void print()
{
for(int i = 1; i <= 6; i++)
{
printf(i!=6?"%d ":"%d\n", save[i]);
}
return ;
}
void dfs(int d)
{
if(ans == 6)
{
print();
return;
}
if(d > n) return ;
save[++ans] = b[d];
dfs(d+1);
--ans;
dfs(d+1);
}
int main()
{
int first = 0;
while(scanf("%d", &n), n)
{
if(first) printf("\n");
first = 1;
ans = 0;
memset(save, 0, sizeof(save));
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
dfs(1);
}
return 0;
}