ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var numbers = make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscanf(reader, "%d ", &numbers[i])
}
var counts = make([]int, 4)
for i := 0; i < 4; i++ {
fmt.Fscanf(reader, "%d ", &counts[i])
}
var max, min, sum, idx = -1000000000, 1000000000, numbers[0], 0
solve(numbers, counts, &max, &min, sum, idx)
fmt.Fprintln(writer, max)
fmt.Fprintln(writer, min)
}
func solve(numbers, counts []int, maxptr, minptr *int, sum, idx int) {
if idx == len(numbers)-1 {
if *maxptr < sum {
*maxptr = sum
}
if *minptr > sum {
*minptr = sum
}
return
}
if counts[0] > 0 {
counts[0]--
solve(numbers, counts, maxptr, minptr, sum+numbers[idx+1], idx+1)
counts[0]++
}
if counts[1] > 0 {
counts[1]--
solve(numbers, counts, maxptr, minptr, sum-numbers[idx+1], idx+1)
counts[1]++
}
if counts[2] > 0 {
counts[2]--
solve(numbers, counts, maxptr, minptr, sum*numbers[idx+1], idx+1)
counts[2]++
}
if counts[3] > 0 {
counts[3]--
solve(numbers, counts, maxptr, minptr, sum/numbers[idx+1], idx+1)
counts[3]++
}
}
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2748๋ฒ / ํผ๋ณด๋์น ์ 2 [Go] (0) | 2020.07.31 |
---|---|
BOJ / 14889๋ฒ / ์คํํธ์ ๋งํฌ [Go] (0) | 2020.07.30 |
BOJ / 2580๋ฒ / ์ค๋์ฟ [Go] (0) | 2020.07.24 |
BOJ / 9663๋ฒ / N-Queen [Go] (0) | 2020.07.23 |
BOJ / 15652๋ฒ / N๊ณผ M (4) [Go] (0) | 2020.07.22 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ชฝ๊ณ ๋๋น
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถํ๋ก
- baekjoon
- ์๋ฐ
- Macbook pro 2012 mid 13
- BFS
- dfs
- BOJ
- ๋ฐฑ์ค
- MongoDB
- ๋ธ๋ฃจํธํฌ์ค
- ๋ฐ๋
- ์๊ณ ๋ฆฌ์ฆ
- ๋ถํ ์ ๋ณต
- ํ
- python3
- dp
- ์ด๋ถํ์
- ๋งฅ๋ถ
- java
- ballet
- ํด์๋งต
- AWS
- Golang
- Algorithm
- ์๊ฐ๊ต์ฒด
- go
- ์คํ
- Total
- Today
- Yesterday