https://school.programmers.co.kr/learn/courses/30/lessons/43163
#include <string>
#include <vector>
using namespace std;
int iReasult = 9999;
bool visit[51];
void dfs(string begin, string target, vector<string>& words, int iCount)
{
if (begin == target)
{
iReasult = min(iCount, iReasult);
return;
}
for (int i = 0; i < words.size(); i++)
{
int iTmp = 0;
if (!visit[i]) //방문안한거
{
for (int j = 0; j < begin.length(); j++)
{
if (begin[j] != words[i][j])
{
iTmp++;
}
}
if (iTmp == 1) //하나다른경우만
{
visit[i] = true;
dfs(words[i], target, words, iCount + 1);
visit[i] = false;
}
}
}
}
int solution(string begin, string target, vector<string> words) {
dfs(begin, target, words, 0);
if (iReasult == 9999) iReasult = 0;
return iReasult;
}
DPS로 해결한 문제
전부 탐색 하는형식으로 count 를 늘려가며 최솟값을 결과로 도출하는 형식이다
어렵다 나중에 다실볼것,,