반응형

www.acmicpc.net/problem/14499

 

14499번: 주사위 굴리기

첫째 줄에 지도의 세로 크기 N, 가로 크기 M (1 ≤ N, M ≤ 20), 주사위를 놓은 곳의 좌표 x y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), 그리고 명령의 개수 K (1 ≤ K ≤ 1,000)가 주어진다. 둘째 줄부터 N개의 줄에 지도

www.acmicpc.net

 

 

 

</p

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define TOP dice[1][1]
#define BOTTOM dice[3][1]
using namespace std;
int n, m, x, y, k, arr[21][21], dice[4][3], cmd;
int dx[] = { 000-11 };    // 1: 동, 2: 서, 3: 북, 4: 남
int dy[] = { 01-100 };
void move(int cmd) {            // 주사위 변경
    int temp;
    // 1. 동쪽
    if (cmd == 1) {
        temp = dice[3][1];
        dice[3][1= dice[1][2];
        dice[1][2= dice[1][1];
        dice[1][1= dice[1][0];
        dice[1][0= temp;
    }
    // 2. 서쪽
    else if (cmd == 2) {
        temp = dice[3][1];
        dice[3][1= dice[1][0];
        dice[1][0= dice[1][1];
        dice[1][1= dice[1][2];
        dice[1][2= temp;
    }
    // 3. 북쪽
    else if (cmd == 3) {
        temp = dice[0][1];
        dice[0][1= dice[1][1];
        dice[1][1= dice[2][1];
        dice[2][1= dice[3][1];
        dice[3][1= temp;
    }
    // 4. 남쪽
    else if (cmd == 4) {
        temp = dice[3][1];
        dice[3][1= dice[2][1];
        dice[2][1= dice[1][1];
        dice[1][1= dice[0][1];
        dice[0][1= temp;
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> x >> y >> k;
    rep(i, n) {
        rep(j, m)
            cin >> arr[i][j];
    }
    while (k--) {
        cin >> cmd;
        int nx = x + dx[cmd];            // 이동할 방향 설정
        int ny = y + dy[cmd];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m) {    // 범위 검사
            move(cmd);
            if (arr[nx][ny] == 0)        // 현재 위치의 숫자가 0이면
                arr[nx][ny] = BOTTOM;    // 주사위 바닥 숫자를 현재 위치에 복사
 
            else {                        // 현재 위치의 숫자가 0 아니면
                BOTTOM = arr[nx][ny];    // 현재 위치의 숫자를 주사위 바닥에 복사하고
                arr[nx][ny] = 0;        // 현재 위치의 숫자를 0으로 변경
            }
            cout << TOP << '\n';
            x = nx;
            y = ny;
        }
    }
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14891  (0) 2021.02.22
백준 14890  (0) 2021.02.21
백준 14501  (0) 2021.02.15
백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
반응형

www.acmicpc.net/problem/14501

 

14501번: 퇴사

첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다.

www.acmicpc.net

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=1;i<=n;i++)
#define pii pair<intint>
using namespace std;
int n, ans = -1;
pii arr[16];
void dfs(int now, int sum) {
    ans = max(ans, sum);
    for (int i = now; i <= n; i++) {                    // 모든 날짜 다 탐색
        if (i + arr[i].first <= n+1)                    // 현재 상담이 n+1일 안에 끝나면
            dfs(i + arr[i].first, sum + arr[i].second);    // 그 날짜로 이동, 돈 더함
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    rep(i, n)
        cin >> arr[i].first >> arr[i].second;
    dfs(10);
    cout << ans;
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14890  (0) 2021.02.21
백준 14499  (0) 2021.02.21
백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
백준 14502  (0) 2021.02.03
반응형

www.acmicpc.net/problem/14500

 

14500번: 테트로미노

폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변

www.acmicpc.net

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 https://velog.io/@skyepodium/%EB%B0%B1%EC%A4%80-14500-%ED%85%8C%ED%8A%B8%EB%A1%9C%EB%AF%B8%EB%85%B8
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n, m, arr[501][501], val=0, ans = 0;
int dx[] = { 10-10 };
int dy[] = { 010-1 };
int ex[4][4= {
    {000-1}, // ㅗ
    {0121}, // ㅏ
    {0001}, // ㅜ
    {0-101// ㅓ
};
int ey[4][4= {
    {0121}, // ㅗ
    {0001}, // ㅏ
    {0121}, // ㅜ
    {0111// ㅓ
};
bool visited[501][501];
void dfs(int x, int y, int cnt) {
    if (cnt == 4) {
        ans = max(ans, val);
        return;
    }
 
    rep(i, 4) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
            if (!visited[nx][ny]) {
                visited[nx][ny] = 1;
                val += arr[nx][ny];
                dfs(nx, ny, cnt + 1);
                val -= arr[nx][ny];
                visited[nx][ny] = 0;
            }
        }
    }
}
void func2(int x, int y) {
    rep(i, 4) {
    int cnt = 0, temp = 0;
        rep(j, 4) {
            int nx = x + ex[i][j];
            int ny = y + ey[i][j];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                temp += arr[nx][ny];
                cnt++;
            }
        }
        if (cnt == 4)
            ans = max(ans, temp);
    }
}
 
void func1(int x, int y) {
    int temp = 0;
    // ㅗ
    if (x - 1 >= 0 && x < n && y >= 0 && y + 2 < m) {
        temp = arr[x][y] + arr[x][y + 1+ arr[x - 1][y + 1+ arr[x][y + 2];
        ans = max(ans, temp);
    }
    // ㅏ
    if (x >= 0 && x + 2 < n && y >= 0 && y + 1 < m) {
        temp = arr[x][y] + arr[x+1][y] + arr[x+2][y] + arr[x+1][y + 1];
        ans = max(ans, temp);
    }
    // ㅜ
    if (x >= 0 && x + 1 < n && y >= 0 && y + 2 < m) {
        temp = arr[x][y] + arr[x][y + 1+ arr[x +1][y + 1+ arr[x][y + 2];
        ans = max(ans, temp);
    }
    // ㅓ
    if (x - 1 >= 0 && x + 1 < n && y >= 0 && y + 1 < m) {
        temp = arr[x][y] + arr[x][y + 1+ arr[x - 1][y + 1+ arr[x+1][y + 1];
        ans = max(ans, temp);
    }
 
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rep(i, n) {
        rep(j, m) {
            cin >> arr[i][j];
        }
    }
 
    rep(i, n) {
        rep(j, m) {
            if (!visited[i][j]) {
                visited[i][j] = 1;
                val += arr[i][j];
                dfs(i, j, 1);
                func2(i, j);
                val -= arr[i][j];
                visited[i][j] = 0;
            }
        }
    }
    cout << ans;
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14499  (0) 2021.02.21
백준 14501  (0) 2021.02.15
백준 15686  (0) 2021.02.05
백준 14502  (0) 2021.02.03
백준 15684  (0) 2021.02.03
반응형

www.acmicpc.net/problem/15686

 

15686번: 치킨 배달

크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸

www.acmicpc.net

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
int n, m, arr[51][51];
int cnt = 0, ans = 987654321;
/*
    도시의 치킨 거리 = 모든 집의 치킨 거리의 합
    치킨 거리 = 현재 집에서 가장 가까운 치킨집과의 거리
    m개 남기고 나머지 다 폐업
*/
int chk() {
    int ret = 0;
    rep(i, n) {
        rep(j, n) {
            if (arr[i][j] == 1) {                                        // 현재 위치가 가정집이면
                int tmp = 987654321;
                rep(a, n) {
                    rep(b, n) {
                        if (arr[a][b] == 2)                                // 모든 치킨집과의 거리 계산
                            tmp = min(tmp, abs(i - a) + abs(j - b));    // 최솟값 저장
                        
                    }
                }
                ret += tmp;                                    // 도시의 치킨 거리 += 현재 집의 치킨 거리
            }
        }
    }
    return ret;
}
void dfs(int x, int y, int now) {
    if (now == m) {                    // m개만 남았으면 거리 체크
        ans = min(ans, chk());
        return;
    }
 
    for (int i = x; i <= n; i++) {
        y = 1;
        for (int j = y; j <= n; j++) {
            if (arr[i][j] == 2) {    // 치킨집 찾으면 0으로 변경
                arr[i][j] = 0;        // 폐업
                dfs(i, j, now - 1);    // 개수 1개 줄이고 계속 탐색
                arr[i][j] = 2;        // 다음 탐색을 위해 복구
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rep(i, n) {
        rep(j, n) {
            cin >> arr[i][j];
            if (arr[i][j] == 2)
                cnt++;
        }
    }
    dfs(11, cnt);
    cout << ans;
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14501  (0) 2021.02.15
백준 14500  (0) 2021.02.13
백준 14502  (0) 2021.02.03
백준 15684  (0) 2021.02.03
백준 14889  (0) 2021.01.29
반응형

www.acmicpc.net/problem/14502

 

14502번: 연구소

인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크

www.acmicpc.net

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define pii pair<intint>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n, m;
int arr[9][9];
int dx[4= { 10-10 };
int dy[4= { 010-1 };
int temp[9][9];
int ans = -1;
int chk_zero() {
    int ret = 0;
    rep(i, n) {
        rep(j, m) {
            if (temp[i][j] == 0)
                ret++;
        }
    }
    return ret;
}
bool visited[9][9];
void bfs() {
    queue<pii> q;
    // 1) 원본 배열 복사 (원본 배열로 하면 다음 bfs 실행 못함)
    rep(i, n) {        
        rep(j, m)    
            temp[i][j] = arr[i][j];
    }
    
    // 2) 모든 칸 탐색 (2 이고 방문 안했으면 q에 추가)
    rep(i, n) {        
        rep(j, m) {    
            if (temp[i][j] == 2 && !visited[i][j]) {
                q.push({ i,j });
                visited[i][j] = 1;
            }
        }
    }
 
    // 3) q에서 꺼내서 처리
    while (!q.empty()) {
        pii now = q.front();
        q.pop();
        int x = now.first;
        int y = now.second;
        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m) {
                if (temp[nx][ny] == 0 && !visited[nx][ny]) {
                    temp[nx][ny] = 2;
                    visited[nx][ny] = 1;
                    q.push({ nx, ny });
                }
            }
        }
    }
}
 
void dfs(int x, int y, int cnt) {
    if (cnt == 3) {
        memset(visited, 0sizeof(visited));
        bfs();                        // 2. bfs로 2 퍼뜨리기
        ans = max(ans, chk_zero());    // 3. 0 개수 확인
        return;
    }
    
    for(int i = x; i<n; i++){        // 1. 벽 세우기(백트래킹)
        for(int j = 0; j<m; j++) {
            if (arr[i][j] == 0) {
                arr[i][j] = 1;    
                dfs(i, j, cnt + 1);
                arr[i][j] = 0;
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    rep(i, n) {
        rep(j, m)
            cin >> arr[i][j];
    }
    dfs(000);
    cout << ans;
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
백준 15684  (0) 2021.02.03
백준 14889  (0) 2021.01.29
백준 14888  (0) 2021.01.28
반응형

www.acmicpc.net/problem/15684

 

15684번: 사다리 조작

사다리 게임은 N개의 세로선과 M개의 가로선으로 이루어져 있다. 인접한 세로선 사이에는 가로선을 놓을 수 있는데, 각각의 세로선마다 가로선을 놓을 수 있는 위치의 개수는 H이고, 모든 세로선

www.acmicpc.net

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, h;
int arr[31][11];
int min_cnt = 987654321;
bool chk() {
    // 마지막 가로줄에 도착했을 때 출발번호와 도착번호 같은지 확인
    for (int i = 1; i <= n; i++) {        // 모든 세로줄 검사
        int current_col = i;            // 현재 세로줄 위치 저장, 가로줄 만나면 변함
        for (int j = 1; j <= h; j++) {    // 모든 가로줄 검사
            if (arr[j][current_col]==1)    // 현재 위치에 사다리가 있으면 그거 타고 오른쪽으로 이동
                current_col++;
            else if (arr[j][current_col - 1]==1)    // 현재 위치의 왼쪽에 사다리 있으면 그거 타고 왼쪽으로 이동
                current_col--;
        }
 
        // 출발번호 도착번호 다르면
        if (current_col != i)
            return false;
    }
    return true;
}
void dfs(int row, int col, int cnt) {
    // cnt가 3보다 크거나 현재 최솟값보다 크거나 같으면 return (더 이상 볼 필요 없음)
    if (cnt > 3 || cnt >= min_cnt) return;
    if (chk()) {
        min_cnt = min(cnt, min_cnt);
        return;
    }
    
    for(int i = row; i<=h; i++) {    // 모든 가로줄 검사
        col = 1;                    // 다음 가로줄 검사할 때 첫 번째 세로줄부터 검사
        for(int j=col; j<n; j++) {    // 모든 세로줄 검사 (마지막 세로줄은 오른쪽 검사 안함)
            if (arr[i][j]==0) {        // 현재 위치에 사다리 없으면
                if (arr[i][j - 1== 0 && arr[i][j + 1== 0) {   // 현재 위치 양 옆에 가로줄이 없어야 함
                    arr[i][j] = 1;
                    dfs(i, j, cnt + 1);
                    arr[i][j] = 0;
                }
            }
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> h;
    for (int i = 1;i <= m;i++) {
        int a, b;
        cin >> a >> b;
        arr[a][b] = 1;
    }
    dfs(110);
 
    cout << (min_cnt == 987654321 ? -1 : min_cnt);
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
백준 14502  (0) 2021.02.03
백준 14889  (0) 2021.01.29
백준 14888  (0) 2021.01.28
반응형

www.acmicpc.net/problem/14889

 

14889번: 스타트와 링크

예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.

www.acmicpc.net

 
1
2
3
4
5
6
7
8
9
10
11
12
13
void dfs(int now, int cnt) {
    if (cnt == n / 2) {
        // 로직 처리
        return;
    }
 
    // 조합 찾기(n개 중 r개)
    for (int i = now; i < n; i++) {
        visited[i] = true;
        dfs(i + 1, cnt + 1);
        visited[i] = false;
    }
}
cs

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int arr[21][21];
int visited[20];
int min_gap = 987654321;
void dfs(int now, int cnt) {
    if (cnt == n / 2) {
        int score1 = 0;
        int score2 = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                // 선택됨 -> 팀1
                if (visited[i] && visited[j])
                    score1 += (arr[i][j] + arr[j][i]);
                // 선택안됨 -> 팀2
                else if (!visited[i] && !visited[j])
                    score2 += (arr[i][j] + arr[j][i]);
            }
        }
        min_gap = min(min_gap, abs(score1 - score2));
        return;
    }
 
    // 조합 찾기(n개 중 r개)
    for (int i = now; i < n; i++) {
        visited[i] = true;
        dfs(i + 1, cnt + 1);
        visited[i] = false;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++
            cin >> arr[i][j];
    }
    
    dfs(00);
    cout << min_gap;
}
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
백준 14502  (0) 2021.02.03
백준 15684  (0) 2021.02.03
백준 14888  (0) 2021.01.28
반응형

www.acmicpc.net/problem/14888

 

14888번: 연산자 끼워넣기

첫째 줄에 수의 개수 N(2 ≤ N ≤ 11)가 주어진다. 둘째 줄에는 A1, A2, ..., AN이 주어진다. (1 ≤ Ai ≤ 100) 셋째 줄에는 합이 N-1인 4개의 정수가 주어지는데, 차례대로 덧셈(+)의 개수, 뺄셈(-)의 개수, 

www.acmicpc.net

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int n;
int arr[11];
int op[4];
int op_arr[10];
int max_val = -987654321;
int min_val = 987654321;
stack<int> s;
stack<int> temp;
void insertData() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
 
    for (int i = 0; i < 4; i++)
        cin >> op[i];
}
void initData() {
    for (int i = n - 1; i >= 0; i--)
        temp.push(arr[i]);
 
    int idx = 0;
    for (int i = 0; i < 4; i++) {
        while (op[i] > 0) {
            op_arr[idx++= i;
            op[i]--;
        }
    }
}
void func() {
    s = temp;
    int op_idx = 0;
    while (s.size() > 1) {
        int result;
        int a = s.top();
        s.pop();
        int b = s.top();
        s.pop();
        if (op_arr[op_idx] == 0)
            result = a + b;
        else if (op_arr[op_idx] == 1)
            result = a - b;
        else if (op_arr[op_idx] == 2)
            result = a * b;
        else if (op_arr[op_idx] == 3)
            result = a / b;
        s.push(result);
        op_idx++;
    }
    int ret = s.top();
    s.pop();
    min_val = min(min_val, ret);
    max_val = max(max_val, ret);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    insertData();
    initData();
 
    func();
    while (next_permutation(op_arr, op_arr + (n - 1))) 
        func();
    cout << max_val << '\n' << min_val;
}
 
cs

 

백트래킹 사용

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int n;
int arr[11];
int op[4];
int max_val = -987654321;
int min_val = 987654321;
 
// cnt: 연산 횟수
void dfs(int temp_val, int cnt) {
    if (cnt == n - 1) {
        min_val = min(min_val, temp_val);
        max_val = max(max_val, temp_val);
        return;
    }
 
    // 백트래킹 부분
    for (int i = 0;i < 4;i++) {        
        if (op[i] != 0) {
            --op[i];            // 사용한 연산자는 개수 빼야함
            if (i == 0
                dfs(temp_val + arr[cnt + 1], cnt+1);
            else if(i == 1)
                dfs(temp_val - arr[cnt + 1], cnt + 1);
            else if (i == 2)
                dfs(temp_val * arr[cnt + 1], cnt + 1);
            else if (i == 3)
                dfs(temp_val / arr[cnt + 1], cnt + 1);
            ++op[i];            // 다음 탐색을 위해서 연산자 개수 복구
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    for (int i = 0; i < 4; i++)
        cin >> op[i];
    dfs(arr[0], 0);
    cout << max_val << '\n' << min_val;
}
 
cs
반응형

'백준 > 삼성기출' 카테고리의 다른 글

백준 14500  (0) 2021.02.13
백준 15686  (0) 2021.02.05
백준 14502  (0) 2021.02.03
백준 15684  (0) 2021.02.03
백준 14889  (0) 2021.01.29

+ Recent posts