baekjoon 20260424
This commit is contained in:
parent
9535c6bd47
commit
388ad7d3a1
1
code_study/Baekjoon/python/16486.py
Normal file
1
code_study/Baekjoon/python/16486.py
Normal file
@ -0,0 +1 @@
|
||||
print((lambda a, b : 2*(a + b*3.141592))(int(input()), int(input())))
|
||||
40
code_study/Baekjoon/swift/2098.swift
Normal file
40
code_study/Baekjoon/swift/2098.swift
Normal file
@ -0,0 +1,40 @@
|
||||
func main() -> Int {
|
||||
guard let N = Int(readLine() ?? "") else { return -1 }
|
||||
|
||||
var W: [[Int]] = []
|
||||
for _ in 0..<N {
|
||||
guard let line = readLine() else { break }
|
||||
let row: [Int] = line.split(separator: " ").compactMap{Int($0)}
|
||||
W.append(row)
|
||||
}
|
||||
|
||||
let INF: Int = 16_000_000
|
||||
var dp: [[Int]] = Array(repeating: Array(repeating: -1, count: 1 << N), count: N)
|
||||
|
||||
func travel(current curr: Int, visited visit: Int) -> Int {
|
||||
if visit == (1 << N - 1) {
|
||||
if W[curr][0] == 0 {
|
||||
return INF
|
||||
}
|
||||
return W[curr][0]
|
||||
}
|
||||
|
||||
if dp[curr][visit] == -1 {
|
||||
dp[curr][visit] = INF
|
||||
|
||||
for nxt in 0..<N {
|
||||
if W[curr][nxt] == 0 || (visit & 1 << nxt) == (1 << nxt) {
|
||||
continue
|
||||
}
|
||||
|
||||
dp[curr][visit] = min(dp[curr][visit], W[curr][nxt] + travel(current: nxt, visited: (visit | (1 << nxt))))
|
||||
}
|
||||
}
|
||||
|
||||
return dp[curr][visit]
|
||||
}
|
||||
|
||||
return travel(current: 0, visited: 1)
|
||||
}
|
||||
|
||||
print(main())
|
||||
Loading…
x
Reference in New Issue
Block a user