[백준 14888번 C/C++] 연산자 끼워넣기
목차
[백준 14888번 C/C++] 연산자 끼워넣기
https://www.acmicpc.net/problem/14888
해결전략
코드
#include <stdio.h>
using namespace std;
int n;
int max=-1000000001;
int min=1000000001;
int a[101], oper[4];
void DFS(int L, int result)
{
if(L==n)
{
if (result > max) max = result;
if (result < min) min = result;
return;
}
for(int i=0; i<4; i++)
{
if(oper[i] > 0 )
{
oper[i]--;
if(i==0) DFS(L+1, result+a[L]);
else if(i==1) DFS(L+1, result-a[L]);
else if(i==2) DFS(L+1, result*a[L]);
else if(i==3) DFS(L+1, result/a[L]);
oper[i]++;
}
}
}
int main() {
freopen("input.txt", "rt", stdin);
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d", &a[i]);
}
for(int i=0; i<4; i++){
scanf("%d", &oper[i]);
}
DFS(1, a[0]);
printf("%d\n", max);
printf("%d\n", min);
return 0;
}
'⭐ 코딩테스트 > 백준' 카테고리의 다른 글
[백준 11729번 C/C++] 하노이 탑 이동 순서 (0) | 2023.05.22 |
---|---|
[백준 24060번 C/C++] 알고리즘 수업 - 병합 정렬 1 (0) | 2023.05.20 |
[백준 1912번 C/C++] 연속합 (0) | 2023.05.18 |
[백준 9184번 C/C++] 신나는 함수 실행 (0) | 2023.05.17 |
[백준 24416번 C/C++] 알고리즘 수업 - 피보나치 수 1 (0) | 2023.05.16 |
댓글
이 글 공유하기
다른 글
-
[백준 11729번 C/C++] 하노이 탑 이동 순서
[백준 11729번 C/C++] 하노이 탑 이동 순서
2023.05.22 -
[백준 24060번 C/C++] 알고리즘 수업 - 병합 정렬 1
[백준 24060번 C/C++] 알고리즘 수업 - 병합 정렬 1
2023.05.20 -
[백준 1912번 C/C++] 연속합
[백준 1912번 C/C++] 연속합
2023.05.18 -
[백준 9184번 C/C++] 신나는 함수 실행
[백준 9184번 C/C++] 신나는 함수 실행
2023.05.17