728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.HashSet;
import java.util.Scanner;
class Solution {
public static int result,n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tc=1;tc<=t;tc++) {
result=0;
n = sc.nextInt();
String word[] = new String[n];
for(int i=0;i<n;i++) {
word[i] = sc.next();
}
combination(0,word,new HashSet<>());
System.out.println("#"+tc+" "+result);
}
}
static void combination(int depth,String[] word,HashSet<Character> s) {
HashSet<Character> hs = new HashSet<>(s);
if(depth==n) { //선택 n개 만큼 하면 종료
if(hs.size()==26) {
result++;
}
return;
}
combination(depth+1,word,hs); //선택 안 함
for(char ch: word[depth].toCharArray()) {
hs.add(ch);
}
combination(depth+1,word,hs); //선택함
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 북북서 (D3) (0) | 2024.10.02 |
|---|---|
| [SW Expert Academy] 상호의 배틀필드 (D3) (1) | 2024.10.02 |
| [SW Expert Academy] 숫자가 같은 배수 (D3) (0) | 2024.10.01 |
| [SW Expert Academy] 알 덴테 스파게티 (D3) (9) | 2024.10.01 |
| [SW Expert Academy] 진용이네 주차타워 (D3) (0) | 2024.10.01 |