티스토리 뷰
출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do
#include <iostream>
#include <algorithm>using namespace std;#define INF 2e9int N, numMAX, numMIN, tmp, tmp2;int op[4], arr[12];void dfs(int num, int count){ if (count == N - 1) { numMAX = max(numMAX, tmp); numMIN = min(numMIN, tmp); return; } for (int i = 0; i < 4; i++) { if (op[i] > 0) { if (i == 0) { tmp = num + arr[count + 1]; op[i]--;dfs(tmp, count + 1);op[i]++; } else if (i == 1) { tmp = num - arr[count + 1]; op[i]--;dfs(tmp, count + 1);op[i]++; } else if (i == 2) { tmp = num * arr[count + 1]; op[i]--;dfs(tmp, count + 1);op[i]++; } else if (i == 3) { tmp = num / arr[count + 1]; op[i]--;dfs(tmp, count + 1);op[i]++; } } }}int main(){ int T; int tc = 1; cin >> T; while (T--) { cin >> N; numMAX = -INF; numMIN = INF; for (int i = 0;i < 4; i++) cin >> op[i]; for (int i = 0; i < N; i++) cin >> arr[i]; dfs(arr[0], 0); cout << "#" << tc++ << " " << numMAX-numMIN << endl; } return 0;}'알고리즘 > SWEA' 카테고리의 다른 글
| [SWEA 4012] 요리사 (0) | 2018.07.23 |
|---|---|
| [SWEA 2115] 벌꿀채취 (0) | 2018.07.23 |
| [SWEA 2112] 보호 필름 (2) | 2018.07.23 |
| [SWEA 2105] 디저트 카페 (0) | 2018.07.23 |
| [SWEA 1949] 등산로 조정 (0) | 2018.07.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 이차원 배열과 연산
- DFS
- STL
- 게리맨더링 2
- hackerrank
- 팁
- SWEA
- 미세먼지 안녕!
- 입출력
- 17143
- boj
- 삼성
- 시간 복잡도
- 2018 KAKAO BLIND RECRUITMENT
- 17779
- 2018 카카오 블라인드 채용
- 알고리즘
- 17140
- 17837
- 역량 테스트
- scanf
- 17142
- DP
- string
- 트렌드
- 백준
- SW Expert Academy
- 17144
- 연구소 3
- 새로운 게임 2
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함