#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int answer = 9;
void dfs(int n, int count, int num, int number) {
if (count > 8)
return;
if (num == number) {
answer = min(answer,count);
return;
}
int index = 0;
for (int i = 0; i < 8; i++) {
index = index * 10 + n;
dfs(n, count + 1 + i, num + index, number);
dfs(n, count + 1 + i, num - index, number);
dfs(n, count + 1 + i, num * index, number);
dfs(n, count + 1 + i, num / index, number);
}
return;
}
int solution(int N, int number) {
dfs(N, 0, 0, number);
if (answer >= 9)
answer = -1;
return answer;
}
프로그래머스