ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/19947
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var h float64
var y int
fmt.Fscanln(reader, &h, &y)
fmt.Fprintln(writer, getMaxProfit(h, y))
}
func getMaxProfit(h float64, y int) float64 {
var dp = make([]float64, y+1)
dp[0] = h
for i := 1; i < y+1; i++ {
dp[i] = float64(int(dp[i-1] * 1.05))
if i >= 3 {
threeYears := float64(int(dp[i-3] * 1.2))
if threeYears > dp[i] {
dp[i] = threeYears
}
}
if i >= 5 {
fiveYears := float64(int(dp[i-5] * 1.35))
if fiveYears > dp[i] {
dp[i] = fiveYears
}
}
}
return dp[y]
}
๐จ Python3
# https://www.acmicpc.net/problem/19947
import sys
def get_max_profit(h, y):
dp = [0 for i in range(y+1)]
dp[0] = h
for i in range(1, y+1):
dp[i] = int(dp[i-1]*1.05)
if i >= 3:
dp[i] = max(int(dp[i-3]*1.2), dp[i])
if i >= 5:
dp[i] = max(int(dp[i-5]*1.35), dp[i])
return dp[y]
if __name__ == "__main__":
h, y = list(map(int, sys.stdin.readline().split()))
print(get_max_profit(h, y))
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 2503๋ฒ / ์ซ์ ์ผ๊ตฌ [Go][Python3] (0) | 2021.01.23 |
---|---|
BOJ / 17626๋ฒ / Four Squares [Go][Python3] (0) | 2021.01.21 |
BOJ / 9655๋ฒ / ๋ ๊ฒ์ [Go][Python3] (0) | 2021.01.19 |
BOJ / 13301๋ฒ / ํ์ผ ์ฅ์๋ฌผ [Go][Python3] (0) | 2021.01.18 |
BOJ / 9625๋ฒ / BABBA [Go][Python3] (0) | 2021.01.17 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ํ
- dfs
- Golang
- baekjoon
- AWS
- python3
- ๋ฐฑ์ค
- ์๋ฐ
- Algorithm
- BFS
- dp
- ์๊ฐ๊ต์ฒด
- MongoDB
- ์๊ณ ๋ฆฌ์ฆ
- ์คํ
- ํด์๋งต
- ๋ธ๋ฃจํธํฌ์ค
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋งฅ๋ถ
- ํ๋ก์ด๋์์ฌ
- ๋งฅ๋ถํ๋ก
- java
- BOJ
- ๋ฐ๋
- ๋ชฝ๊ณ ๋๋น
- ballet
- Macbook pro 2012 mid 13
- go
- ์ด๋ถํ์
- ๋ถํ ์ ๋ณต
- Total
- Today
- Yesterday