-
Notifications
You must be signed in to change notification settings - Fork 0
/
1023.cpp
43 lines (39 loc) · 994 Bytes
/
1023.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define S "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
using namespace std;
void solve(char a[], bool b[], int n, int k, int i, int &c){
if(c < k){
for(int j = 0; j < n; j++){
if(b[j] == false){
a[i] = S[j];
if(i == n - 1){
c++;
for(int ii = 0; ii < n; ii++){
printf("%c", a[ii]);
}
printf("\n");
}else{
b[j] = true;
solve(a, b, n, k, i + 1, c);
b[j] = false;
}
}
}
}
}
int main(){
int t, n, k;
scanf("%d", &t);
for(int i = 1; i <= t; i++){
scanf("%d %d", &n, &k);
char a[n];
bool b[n];
int c = 0;
memset(b, false, sizeof b);
printf("Case %d:\n", i);
solve(a, b, n, k, 0, c);
}
}