ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

19947๋ฒˆ: ํˆฌ์ž์˜ ๊ท€์žฌ ๋ฐฐ์ฃผํ˜•

2020๋…„์— ํ•™๊ต๋กœ ๋ณตํ•™ํ•œ ์ฃผํ˜•์ด๋Š” ์›”์„ธ๋ฅผ ๋งˆ๋ จํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ตฐ ์ ๊ธˆ์„ ๊นจ๊ณ  ๋ณต๋ฆฌ ํˆฌ์ž๋ฅผ ํ•˜๋ ค๊ณ  ํ•œ๋‹ค. ์ฃผํ˜•์ด๊ฐ€ ํ•˜๋ ค๋Š” ํˆฌ์ž์—๋Š” 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•์˜ ํˆฌ์ž ๋ฐฉ์‹์ด ์žˆ๋‹ค.  1๋…„๋งˆ๋‹ค 5%์˜ ์ด์œจ์„ ์–ป๋Š” ํˆฌ์ž (

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ 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
๋Œ“๊ธ€