ํฐ์คํ ๋ฆฌ ๋ทฐ
dev/algorithm
BOJ / 17212๋ฒ / ๋ฌ๋๋ผ ํ ๋ผ๋ฅผ ์ํ ๊ตฌ๋งค๋๊ธ ์ง๋ถ ๋์ฐ๋ฏธ [Go][Python3]
crscnt 2021. 3. 10. 21:00๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/17212
package main
import (
"bufio"
"fmt"
"os"
)
var (
dp []int
coins = []int{7, 5, 2, 1}
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
dp = make([]int, n+1)
for i := 1; i < n+1; i++ {
dp[i] = 100000
}
for i := 1; i < n+1; i++ {
for _, coin := range coins {
if i-coin >= 0 && dp[i-coin]+1 < dp[i] {
dp[i] = dp[i-coin] + 1
}
}
}
fmt.Fprintln(writer, dp[n])
}
๐จ Python3
# https://www.acmicpc.net/problem/17212
import sys
dp = []
coins = [7, 5, 2, 1]
if __name__ == "__main__":
n = int(sys.stdin.readline())
dp = [100000 for _ in range(n+1)]
dp[0] = 0
for i in range(1, n+1):
for coin in coins:
if i-coin >= 0 and dp[i-coin]+1 < dp[i]:
dp[i] = dp[i-coin] + 1
print(dp[n])
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2847๋ฒ / ๊ฒ์์ ๋ง๋ ๋์ค์ด [Go][Python3] (0) | 2021.03.12 |
---|---|
BOJ / 15828๋ฒ / Router [Go][Python3] (0) | 2021.03.11 |
BOJ / 1010๋ฒ / ๋ค๋ฆฌ ๋๊ธฐ [Go][Python3] (0) | 2021.03.09 |
BOJ / 8394๋ฒ / ์ ์ [Go][Python3] (0) | 2021.03.08 |
BOJ / 13699๋ฒ / ์ ํ์ [Go][Python3] (0) | 2021.03.07 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- BFS
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถํ๋ก
- ์๊ณ ๋ฆฌ์ฆ
- Macbook pro 2012 mid 13
- java
- MongoDB
- ๋ฐ๋
- ๋ธ๋ฃจํธํฌ์ค
- Golang
- ํ
- ์คํ
- ๋ชฝ๊ณ ๋๋น
- baekjoon
- go
- ๋ถํ ์ ๋ณต
- ์๊ฐ๊ต์ฒด
- ballet
- ๋ฐฑ์ค
- AWS
- Algorithm
- ์ด๋ถํ์
- dp
- ๋งฅ๋ถ
- ์๋ฐ
- dfs
- ํ๋ก์ด๋์์ฌ
- python3
- BOJ
- ํด์๋งต
- Total
- Today
- Yesterday