[SWEA] 9480 민정이와 광직이의 알파벳 공부

Time Lapse :5min 0sec

9480.c

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 <iostream>
#include <memory.h>
#include <string>
using namespace std;
bool arr[16][26];
int answer;
int N, TC;
string s;
void DFS(int index,bool cur[]) {
if (index == N) {
for (int i = 0; i < 26; i++) {
if (!cur[i])
return;
}
++answer;
return;
}
bool next_cur[26];
memcpy(next_cur, cur, sizeof(next_cur));
DFS(index + 1, next_cur);
for (int i = 0; i < 26; i++) {
if (arr[index][i])
next_cur[i] = true;
}
DFS(index + 1, next_cur);
}

int main(int argc, char** argv) {
scanf("%d",&TC);
bool cur[26] = { false, };
for (int i = 1; i<=TC; i++) {
scanf("%d",&N);
memset(arr, false, sizeof(arr));
answer = 0;
for (int j = 0; j < N; j++) {
cin >> s;
for (int k = 0; k < s.length(); k++)
arr[j][s[k] - 'a'] = true;
}
DFS(0, cur);
printf("#%d %d\n", i, answer);
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/9480/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.