๋ฌธ์ :
https://www.acmicpc.net/problem/1049
๋ถ์ :
๋จ์ํ ๊ตฌํ ๋ฌธ์ ์๋ค. ๋ชจ๋ ๋ธ๋๋ ์ค์์ ํจํค์ง์ ๋จํ์ผ๋ก ๊ตฌ๋งคํ์๋ ๊ฐ๊ฒฉ ๋น๊ต๋ฅผ ํตํด ์ต์๊ฐ์ choose ๋ณ์์ select์ ์ ์ฅํ ๋ค, n์ ๊ฐ์ ์ค์ฌ๋๊ฐ๋ฉฐ minPrice๋ฅผ ์ ๋ฐ์ดํธ ํ๋ค.
Swift ์ฝ๋ :
//
// main.swift
// SOMA๐ฉ๐ป๐ป
//
// Created by JoSoJeong on 2022/04/13.
//
import Foundation
var line = readLine()!.split(separator: " ").map { Int(String($0))! }
var n = line[0]
var Tcase = line[1]
var brand = [(Int, Int)]()
for i in 0..<Tcase {
var line = readLine()!.split(separator: " ").map { Int(String($0))! }
brand.append((line[0], line[1]))
}
var minPrice = 0
while n != 0 {
var select = 100000
for i in brand {
var choose = 100000
if n < 6 {
//choose package or one
choose = min(i.0, i.1 * n)
}else {
choose = min(i.0, i.1 * 6)
}
select = min(select, choose)
}
minPrice += select // ์ต์๊ฐ ์
๋ฐ์ดํธ
if(n < 6) {
break
}else {
n = n - 6
}
}
print(minPrice)
'Algorithm๐ฐ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] Swift 2302 ๊ทน์ฅ ์ข์ DP (0) | 2022.04.17 |
---|---|
[๋ฐฑ์ค] Swift 1309 ๋๋ฌผ์ DP (0) | 2022.04.16 |
[๋ฐฑ์ค] Swift 20361 ์ผ์ฐ๋ ์ผ๋ฐ์๊พผ implementation (0) | 2022.04.12 |
[๋ฐฑ์ค] Swift 9466 ํ ํ๋ก์ ํธ DFS (0) | 2022.04.12 |
[๋ฐฑ์ค] Swift 2529 ๋ถ๋ฑํธ backtracking (0) | 2022.04.07 |
๋๊ธ