Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created March 7, 2014 08:40
Show Gist options
  • Save KT-Yeh/9407762 to your computer and use it in GitHub Desktop.
Save KT-Yeh/9407762 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <algorithm>
using namespace std;
int N, S[100], choosed[100], ans[100];
void func(int len, int pos)
{
if (len == 6){
for (int i = 0; i < 5; ++i)
printf("%d ", ans[i]);
printf("%d\n", ans[5]);
return;
}
for (int i = pos; i < N; ++i) {
if (!choosed[i]) {
choosed[i] = 1;
ans[len] = S[i];
func(len+1, i + 1);
choosed[i] = 0;
}
}
}
int main()
{
int Case = 0;
while (scanf("%d", &N) && N) {
if (Case++) printf("\n");
for (int i = 0; i < N; ++i){
scanf("%d", &S[i]);
choosed[i] = 0;
}
func(0,0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment