yuns
[9480/ C++] 민정이와 광직이의 알파벳 공부 본문
반응형
#include <iostream>
#define endl '\n'
#define MAXN 16
using namespace std;
int arr[MAXN];
int n, cnt;
int cmp = (1 << 26) - 1; // 0b11111111111111111111111111
void dfs(int idx, int cur){
if(n == idx) {
if(cur == cmp) cnt++;
return;
}
dfs(idx + 1, cur | arr[idx]);
dfs(idx + 1, cur);
}
int main(){
cin.tie(nullptr) -> sync_with_stdio(false);
int T;
cin >> T;
for(int tc = 1; tc <= T; ++tc){
cin >> n;
cnt = 0;
for(int i = 0; i < n; i++){
int val = 0;
string str;
cin >> str;
for(int j = 0; j < str.size(); j++){
val |= 1 << (str[j] - 'a');
}
arr[i] = val;
}
dfs(0, 0);
cout << '#' << tc << ' ' << cnt << endl;
}
}
반응형
Comments