-
Notifications
You must be signed in to change notification settings - Fork 4
/
Lv1_N으로표현.cpp
31 lines (28 loc) · 764 Bytes
/
Lv1_N으로표현.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <string>
#include <vector>
#include<algorithm>
using namespace std;
int mincount = -1;
void go(int N, int number, int result, int count) {
if (count > 8) { // 종료조건
return;
}
if (number == result) { // 완료조건
if (count < mincount || mincount == -1) { // 원래 answer값보다 작으면 넣어줌
mincount = count;
}
return;
}
int nn = 0;
for (int i = 0; i < 8; i++) {
nn = nn * 10 + N; // N, NN, NNN, NNNN .....
go(N, number, result + nn, count + 1 + i); // i는 N이 몇개 붙어있는 지
go(N, number, result * nn, count + 1 + i);
go(N, number, result - nn, count + 1 + i);
go(N, number, result / nn, count + 1 + i);
}
}
int solution(int N, int number) {
go(N, number, 0, 0);
return mincount;
}