●문제

●입출력

문제풀이
A
AA
AAA
AAAA
AAAAA
AAAAE
AAAAI
AAAAO
AAAU
AAAE
AAAI
AAAO
AAAU
AAAU
AAE
AAI
AAO
AAU
AE
AI
AO
AU 식 한마디로 사전식으로 들어간다
문제풀이
DFS를 사용하여 한개씩 추가하여 TARGET이 맞으면 RETURN
#include <string>
#include <vector>
using namespace std;
int cnt = -1;
int answer = 0;
string target = "";
string aeiou = "AEIOU";
void DFS(string word)
{
cnt++;
if (word == target)
{
answer = cnt;
return;
}
if (word.length() >= 5)
return;
for (int i = 0; i < 5; i++)
{
DFS(word + aeiou[i]);
}
}
int solution(string word)
{
target = word;
DFS("");
return answer;
}
레벨 : 2
점수 : 1
'C++ 프로그래머스 > BFS , DFS' 카테고리의 다른 글
| 프로그래머스(C++) - 여행경로 (0) | 2025.10.05 |
|---|---|
| 프로그래머스(C++) - 단어 변환 (0) | 2025.09.23 |
| 프로그래머스(C++) - 게임 맵 최단거리 (0) | 2025.09.14 |
| 프로그래머스(C++) - 네트워크 (0) | 2025.09.13 |
| 프로그래머스(C++) - 타겟 넘버 (0) | 2025.09.13 |
