슈콩

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

Algorithms/SWEA

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

shukong 2025. 11. 15. 19:13

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXAdrmW61ssDFAXq

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	static int n,result;
	static String[] words;
	static boolean[] visit;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			n = Integer.parseInt(br.readLine());
			words = new String[n];
			for(int i=0;i<n;i++) {
				words[i] = br.readLine();
			}
			result = 0;
			for(int i=1;i<=n;i++) {
				visit = new boolean[n];
				combi(0,0,i);
			}
			System.out.println("#"+tc+" "+result);
		}
	}
	private static void combi(int idx,int cnt,int max) {
		if(cnt==max) {
			HashSet<Character> hs = new HashSet<>();
			for(int i=0;i<n;i++) {
				if(visit[i]) {
					for(char c : words[i].toCharArray()) {
						hs.add(c);
					}
				}
			}
			if(hs.size()==26) result++;
			return;
		}
		for(int i=idx;i<n;i++) {
			if(!visit[i]) {
				visit[i] = true;
				combi(i+1,cnt+1,max);
				visit[i] = false;
			}
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 코딩 토너먼트1  (0) 2025.11.15
[SWEA] 영준이의 카드 카운팅  (0) 2025.11.15
[SWEA] 이진수 표현  (0) 2025.11.15
[SWEA] 체스판 위의 룩 배치  (0) 2025.11.15
[SWEA] 무한 문자열  (0) 2025.11.15