---
layout: post
title:  " SW Expert Academy - 숫자 만들기 "
excerpt: "SWEA_4008"
date:   2018-05-12
cate : "algorithm"
tag:
- SW Expert Academy
---

## Problem 
Problem URL : **[숫자 만들기](https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIeRZV6kBUDFAVH)**

---

## [1] Answer Code (18. 05. 12)

{% highlight cpp %}

#include<iostream>
#include<cstring>
#define ll long long
using namespace std;

int n;
int cal[4];
int arr[12];
ll ans_max,ans_min;


ll func_cal(int idx, int cal_idx, ll sum){
    if(cal_idx == 0)
        return sum + arr[idx];
    else if(cal_idx == 1)
        return sum - arr[idx];
    else if(cal_idx == 2)
        return sum * arr[idx];
    else
        return sum / arr[idx];
}

void dfs(int idx, ll sum){
    if( idx == n-1){
        ans_max = ans_max > sum ? ans_max : sum;
        ans_min = ans_min > sum ? sum : ans_min;
    }
    else {
        for(int i=0; i<4; i++){
            if( cal[i] ){
                cal[i]--;
                dfs(idx+1,func_cal(idx+1,i,sum));
                cal[i]++;
            }
        }
    }
}


int main(){
    int TC;
    cin >> TC;
    
    for(int tc=1; tc<=TC; tc++){
        memset(cal,0,sizeof(cal));
        memset(arr,0,sizeof(arr));
        
        ans_max = 2e9 * -1;
        ans_min = 2e9;

        cin >> n;
        
        for(int i=0; i<4; i++) scanf("%d",cal+i);
        for(int i=0; i<n; i++) scanf("%d",arr+i);
        
        dfs(0,arr[0]);
        printf("#%d %lld\n",tc, ans_max-ans_min);
    }
    return 0;
}


{% endhighlight %}



---

## Code Review

* SW Expert Academy 문제.

* 20분 걸림

* Easy Problem


Modify SW Expert Academy Algorithm Post ' 숫자 만들기 '
Modify SW Expert Academy Algorithm Post ' 숫자 만들기 '
