ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/14501
package main
import (
"bufio"
"fmt"
"os"
)
var (
result int
infos []Info
n int
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
fmt.Fscanln(reader, &n)
for i := 0; i < n; i++ {
var time, profit int
fmt.Fscanln(reader, &time, &profit)
infos = append(infos, Info{time, profit})
}
getMax(0, 0)
fmt.Fprintln(writer, result)
}
type Info struct {
time int
profit int
}
func getMax(index, profit int) {
if index == n {
if result < profit {
result = profit
}
return
}
if index > n {
return
}
getMax(index+infos[index].time, profit+infos[index].profit) // ํด๋น ๋ ์ง์ ์๋ด์ ํ๋ ๊ฒฝ์ฐ
getMax(index+1, profit) // ํด๋น ๋ ์ง์ ์๋ด์ ํ์ง ์๋ ๊ฒฝ์ฐ
}
๐จ Python3
# https://www.acmicpc.net/problem/14501
import sys
result = 0
n = 0
infos = []
def get_max(index, profit):
global result
if index == n:
if result < profit:
result = profit
return
if index > n:
return
get_max(index+infos[index][0], profit+infos[index][1])
get_max(index+1, profit)
if __name__ == "__main__":
n = int(sys.stdin.readline())
for i in range(0, n):
time, profit = list(map(int, sys.stdin.readline().split()))
infos.append((time, profit))
get_max(0, 0)
print(result)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 14697๋ฒ / ๋ฐฉ ๋ฐฐ์ ํ๊ธฐ [Go][Python3] (0) | 2021.01.16 |
---|---|
BOJ / 2309๋ฒ / ์ผ๊ณฑ ๋์์ด [Go][Python3] (0) | 2021.01.15 |
BOJ / 11727๋ฒ / 2รn ํ์ผ๋ง 2 [Go][Python3] (0) | 2021.01.13 |
BOJ / 11726๋ฒ / 2รn ํ์ผ๋ง [Go][Python3] (0) | 2021.01.12 |
BOJ / 2193๋ฒ / ์ด์น์ [Go][Python3] (0) | 2021.01.11 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์คํ
- ๋งฅ๋ถํ๋ก
- ๋ธ๋ฃจํธํฌ์ค
- ๋ชฝ๊ณ ๋๋น
- ์ด๋ถํ์
- ํ
- ballet
- dfs
- ๋ถํ ์ ๋ณต
- MongoDB
- BFS
- ํด์๋งต
- ๋ฐ๋
- ์๋ฐ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- go
- BOJ
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถ
- Golang
- ๋ฐฑ์ค
- ์๊ฐ๊ต์ฒด
- baekjoon
- AWS
- Algorithm
- Macbook pro 2012 mid 13
- ์๊ณ ๋ฆฌ์ฆ
- dp
- java
- Total
- Today
- Yesterday