Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- C/C++ 구현
- AVL 시간 복잡도
- 백준 5397
- 게리멘더링2
- c#
- 백준 1406
- Stack 이란
- 원판 돌리기
- qorwns
- 시간 복잡도
- 백준 17822
- 백준 17471
- 백준
- 해시구현
- dfs
- 버킷 정렬
- 해시 구현
- heap
- 백준 17779
- 백준 1158
- 백준 2447
- 구현
- 풀이
- ㅣ풀이
- 자료구조
- 별 찍기 10
- 5397
- 1764
- 스택의 특징
- 조세퍼스 순열
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 14888] 연산자 끼워넣기 본문
분류
dfs
요구사항
주어진 연산자와 숫자를 사용해서 최대 값과 최소 값 구하기
풀이
숫자는 고정되어 있으니, 연산자의 순서만 고려하면 된다
주어진 숫자대로 연산자를 사용할 수 있다.
조건이 만족할때 연산자를 사용 -> 다음 이동 식으로 풀이하면 된다
ㄹ
#include <iostream>
#include <queue>
#include <algorithm>
#include <string.h>
#include <vector>
#include <string>
using namespace std;
//&:0 *:1 [] :2
int n;
int map[14];
int a, b, c, d;
long long Mans = -987654321;
long long mans = 987654321;
// 플 마 곱 나
void solve(int x, int y, int w, int z, long long sum,int cnt) {
if (x + y + w + z == a + b + c + d) {
Mans = max(Mans, sum);
mans = min(mans, sum);
return;
}
if (x < a) {
solve(x+1,y,w,z,sum+map[cnt],cnt+1);
}
if (y < b) {
solve(x, y+1, w, z, sum - map[cnt], cnt + 1);
}
if (w < c) {
solve(x, y, w+1, z, sum * map[cnt], cnt + 1);
}
if (z < d) {
solve(x, y, w, z+1, sum / map[cnt], cnt + 1);
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &map[i]);
}
scanf("%d%d%d%d", &a, &b, &c, &d);
solve(0, 0, 0, 0, map[0],1);
cout << Mans << endl;
cout << mans << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 18808] 스티커 붙이기 (0) | 2020.05.25 |
---|---|
[백준 3568] iSharp (0) | 2020.05.18 |
[백준 16956] 늑대와 양 (0) | 2020.05.16 |
[백준 14501] 퇴사 (0) | 2020.05.16 |
[백준 17472] 다리 만들기2 (0) | 2020.05.14 |
Comments