Skip to content

Conversation

@sep037
Copy link
Collaborator

@sep037 sep037 commented May 24, 2025

#29

πŸ”— 문제 링크

퇴사
μ·¨μ§ν•˜μ§€λ„ μ•Šμ•˜λŠ”λ° ν‡΄μ‚¬ν•˜κ³  μ‹Άλ‹€

스크란샷 2025-05-24 10 12 42

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

일단 μ²˜μŒμ—” 일수 λ‹Ή κ°€μž₯ 많이 벌 수 μžˆλŠ” μͺ½μœΌλ‘œ μƒκ°ν–ˆλ‹€κ°€
λ‹€μ‹œ μƒκ°ν•΄λ³΄λ‹ˆ 그것도 μΌμˆ˜κ°€ μ•ˆ 맞으면 μ•ˆλ  것 κ°™μ•„μ„œ
μ–Œμ „ν•˜κ²Œ 첫 λ‚ λΆ€ν„° 일수 λŠ˜λ €κ°€λ©° κ΅¬ν–ˆμ–΄μš”

ν•¨μˆ˜ (λ‚ μ§œ, 수읡) {
if λ‚ μ§œκ°€ 총 일 μˆ˜λ³΄λ‹€ 크면
μ΅œλŒ€ 수읡 κ°±μ‹ 
끗

if ν•΄λ‹Ή 일 수λ₯Ό λ”ν–ˆλŠ”λ°λ„ 총 일 μˆ˜λ³΄λ‹€ μž‘μœΌλ©΄
// 상담 μ§„ν–‰

상담을 ν•˜μ§€ μ•ŠμœΌλ©΄
κ·Έλƒ₯ λ‚ μ§œμ— +1

πŸ“š μ–΄λ €μ› λ˜ λ‚΄μš©

μž¬κ·€ 생각이 잘 μ•ˆ λ‚˜μš” . . πŸ₯Ή

Copy link
Member

@giljihun giljihun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 30λΆ„λ§Œμ— ν‘Έμ…¨λ‹€λ‹ˆ DOG GOSUλ„€μš” κΈ€λ‘œλ‹ˆ.
저도 μ†”λ£¨μ…˜ νŒŒνŠΈλŠ” μ™„μ „ λΉ„μŠ·ν•˜κ²Œ ν’€μ—ˆκ±°λ“ μš”!

근데 이 λ¬Έμ œλŠ” 완전탐색은 λ§žμ§€λ§Œ
λΆ„λ₯˜λ₯Ό μ™„μ „νƒμƒ‰μœΌλ‘œ ν•˜κΈ° λ³΄λ‹€λŠ”,
μ €λŠ” λ°±νŠΈλž˜ν‚Ή λ°©μ‹μ˜ dfsλŠλ‚Œμ΄ κ°•ν•˜λ‹€κ³  μƒκ°ν–ˆμ–΄μš”!

λ¬Όλ‘  μž¬κ·€ 말씀 ν•˜μ‹ κ±Έ λ³΄λ‹ˆ 같은 생각을 ν•˜μ…¨μ„ 것 κ°™μ§€λ§Œ, 이 λΆ€λΆ„ λ‹€μ‹œ 체크해봐도 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€
휠릴리~
image

μž…λ ₯λΆ€λ§Œ μ²¨λΆ€ν•©λ‹ˆλ‹€!

import Foundation

/*
 μˆœμ„œλŒ€λ‘œ λ‚ μ§œλ₯Ό λ”ν–ˆμ„λ•Œ N일이 λ‚˜μ˜€λŠ” 경우의 수, 가격을 κ΅¬ν•΄μ„œ
 μ΅œλŒ€κ°’ κ°±μ‹ ?
 */


// μž…λ ₯λΆ€
guard let N = Int(readLine() ?? ""),
      N >= 1, N <= 15 else { exit(0) }

var schedule: [(Int, Int)] = []

(0..<N).forEach { _ in
    guard let input = readLine()?.split(separator: " "),
          input.count == 2,
          let day = Int(input[0]),
          let time = Int(input[1]) else { exit(0) }
    schedule.append((day, time))
}

import Foundation

let N = Int(readLine()!)!
var profitFromWork : [(Int, Int)] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ³€μˆ˜λͺ… μ™„λ²½ν•©λ‹ˆλ‹€. ^^..

Copy link
Collaborator Author

@sep037 sep037 May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹γ…‹ γ„±γ……ν•©λ‹ˆλ‹€ ! 더 λ©‹μ§„ λ³€μˆ˜λͺ… μ§“κ³  싢은데 μ €λ ‡κ²Œ 직관적인 게 더 νŽΈν•΄μš” 사싀 .

@sep037
Copy link
Collaborator Author

sep037 commented May 25, 2025

@giljihun κ°€λ“œλ¬Έμ˜ μ‹  길씨
항상 μ—¬λŸ¬ 방법 μ œμ‹œν•΄μ£Όμ…”μ„œ κ°μ‚¬ν•΄μš”
문제λ₯Ό 보고 μ—¬λŸ¬ 방법을 μ–Έμ œμ―€ λ– μ˜¬λ¦΄ 수 μžˆμ„κΉŒμš” μ–΄λ €μ›Œμš”
λ‹˜μ΄ 더 DOG GOSUμ‹œλ„€μš”

@giljihun
Copy link
Member

μΆ”κ°€μ μœΌλ‘œ.. μ „λž΅μ— λ³΄λ‹ˆκΉŒ
dpκ°€ μžˆλŠ”λ° 제 λ¨Έλ¦¬λ‘œλŠ” dp식 정립이 잘 μ•ˆλ˜λ„€μš”
λ‹€λ₯Έ λΆ„λ“€ dp풀이 κΈ°λŒ€ν•©λ‹ˆλ‹€..!

Copy link
Collaborator

@bishoe01 bishoe01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30λΆ„ 걸리신거 λ¦¬μŠ€νŽ™..

μ €λŠ” 1μ‹œκ°„μ„ ν›Œμ©λ„˜κ²ΌμŠ΅λ‹ˆλ‹€..

저도 λ‹€λ₯ΈλΆ„λ“€μ²˜λŸΌ dfs μΌμŠ΅λ‹ˆλ‹€.
μ²˜μŒμ—λŠ” 이걸 λ’€μ—μ„œλΆ€ν„° κΊΌλ‚΄λ©΄μ„œ 보면 μ’€ λ‹€λ₯ΌκΉŒ?ν•΄μ„œ tmpArr을 reverse둜 λ’€μ§‘κ³  ν”„λ¦°νŠΈμ°μ–΄λ³΄λ‹€κ°€ κ²°κ΅­ μ‹€νŒ¨ν•˜κ³  DFS둜..

μˆ˜λ„μ½”λ“œ

  1. ν‡΄μ‚¬μƒνƒœμΈ 것듀 λ‹€ 걸러주기
  2. dfs둜 ν•΄λ‹Ήλ‚ μ§œμ—μ„œ 회의λ₯Ό μ‹œμž‘ν–ˆμ„λ•Œμ™€ μ•ˆν–ˆμ„λ•Œλ₯Ό λŒλ €μ£Όλ©΄μ„œ μ΅œλŒ€κ°’ μ°ΎκΈ°
  3. dayκ°€ N보닀 컀지면 이제 λ‹€ λŒμ•˜μœΌλ‹ˆ μ’…λ£Œ

살짝 λ‹€λ₯Έμ 

  1. μ‹œκ°„μ„ μ‘°κΈˆμ΄λΌλ„ μ€„μ΄κ³ μž ν•œλ°”ν€΄λŒλ©΄μ„œ endκ°€ 퇴사일 이후에 μžˆλŠ” 애듀은 μ• μ΄ˆμ— ν›„λ³΄κ΅°μ—μ„œ μ—†μ• μ£Όκ³  μ‹œμž‘ν–ˆμ–΄μš”.
  2. index λ₯Ό 1λΆ€ν„°μ‹œμž‘ν•˜κ²Œ ν•΄μ£Όλ €κ³  쑰정을 ν•΄μ€¬μ—ˆμŠ΅λ‹ˆλ‹€ ! 6μΌμ—μ‹œμž‘ν•΄μ„œ ν•˜λ£¨λ©΄ start - 6 , end - 6
typealias Talk = (start: Int, end: Int, profit: Int)

func solution(_ N: Int, _ arr: [(Int, Int)]) -> Int {
    var answer = 0
    var tmpArr = [Talk]()

    func dfs(day: Int, profit: Int) {
        if day > N {
            answer = max(answer, profit)
            return
        }
        if let talk = tmpArr.first(where: { $0.start == day }) {
            dfs(day: talk.end + 1, profit: profit + talk.profit)
        }

        dfs(day: day + 1, profit: profit)
    }

    for (idx, item) in arr.enumerated() {
        let start = idx + 1
        let end = start + item.0 - 1
        let profit = item.1
        // 일단 완성일 κΈ°μ€€ ν‡΄μ‚¬μƒνƒœμΈκ±° λ‹€ 걸러주기
        if end <= N {
            tmpArr.append((start: start, end: end, profit: profit))
        }
    }

    dfs(day: 1, profit: 0)
    return answer
}

μ•„μ‰¬μš΄μ 

if let talk = tmpArr.first(where: { $0.start == day }) {
            dfs(day: talk.end + 1, profit: profit + talk.profit)
        }

이게 tmpArr ꡳ이 κ±ΈλŸ¬μ£Όμ§€ μ•Šμ•˜μœΌλ©΄ 무쑰건 startκ°€ μžˆμ„κ±°λΌ κ·Έλƒ₯ if let ꡳ이 ν•„μš” μ—†μ—ˆκ³  κ°•μ œμ–Έλž˜ν•‘ 써도 됐을 λ“―, νšŒμ˜κ°€ 맀일 μ‹œμž‘ν•˜λ‹ˆκΉŒ

Copy link
Member

@alstjr7437 alstjr7437 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ­”κ°€ dp둜 될 것 같은데 λ„μ €νžˆ 아이디어가 생각이 μ•ˆλ‚˜μ„œ 인터넷을 μ°Έκ³ ν•΄μ„œ

dp둜 ν’€μ–΄λ΄€μŠ΅λ‹ˆλ‹€~~

let N = Int(readLine()!)!
var schedule = [(0,0)]

for _ in 0..<N {
    let input = readLine()!.split(separator: " ").map{ Int($0)! }
    schedule.append((input[0], input[1]))
}

var dp = Array(repeating: 0, count: N+2)

for i in 1..<N+1 {
    // λ‹€μŒλ‚ λ‘œ λ„˜μ–΄κ°ˆλ•Œλ„ μ΅œλŒ€ 보상을 μ΄μ–΄λ‚˜κ°€μ•Όν•¨
    if dp[i] > dp[i+1] { dp[i+1] = dp[i] }
    
    // 퇴사날 보닀 μˆ«μžκ°€ λ†’μœΌλ©΄ κΈ‰μ—¬κ°€ μ•ˆμ±„μ›Œμ§€λ―€λ‘œ continue
    guard i+schedule[i].0 <= N+1 else { continue }
    
    dp[i + schedule[i].0] = max(
        schedule[i].1 + dp[i],           // 였늘 μƒλ‹΄ν•˜κ³  보상 λ°›λŠ” 경우
        dp[i + schedule[i].0]            // 기쑴에 κ·Έ λ‚ κΉŒμ§€ μŒ“μΈ 보상
    )
}

print(dp.max()!)

Comment on lines +26 to +30
if day + profitFromWork[day].0 <= N {
workTime(day: day + profitFromWork[day].0, profit: profit + profitFromWork[day].1)
}
workTime(day: day + 1, profit: profit)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

옹 μž¬κ·€ν•¨μˆ˜λ₯Ό μ΄μš©ν•΄μ„œ μ „μ—­ λ³€μˆ˜μ— maxλ₯Ό μ‚¬μš©ν•΄μ„œ κ΅¬ν˜„ν•˜μ…¨λ„€μš”!!

Copy link
Collaborator

@MuchanKim MuchanKim May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μž…λ ₯ κ°’ μ΅œλŒ€μΉ˜κ°€ 15λΌμ„œ μ™„νƒν•˜λ©΄ λ˜κ² λ‹€ 생각을 ν–ˆλŠ”λ° μž¬κ·€λ‘œ 잘 κ΅¬ν˜„ν•˜μ‹  λ“―!

| 2μ°¨μ‹œ | 2025.04.10 | DFS | [트리의 λΆ€λͺ¨ μ°ΎκΈ°](https://www.acmicpc.net/problem/11725)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/12|
| 3μ°¨μ‹œ | 2025.04.28 | μ •λ ¬ | [접미사 λ°°μ—΄](https://www.acmicpc.net/problem/11656)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/13|
| 4μ°¨μ‹œ | 2025.05.11 | DP | [1, 2, 3 λ”ν•˜κΈ°](https://www.acmicpc.net/problem/9095)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/21|
| 5μ°¨μ‹œ | 2025.05.24 | BruteForce | [퇴사](https://www.acmicpc.net/problem/14501)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/29|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dfs둜 ν’€μ—ˆλŠ”λ° μ™œ μ—¬κΈ° 브루트포슀둜 λ„£μ—ˆμ–΄μš” λ§ˆμΉ΄λ‘œλ‹ˆμ”¨ γ…‹γ…‹

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν—‰ 이게 뭐야

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κΈ°μ–΅ μ•ˆλ‚¨ ;;

Comment on lines +16 to +17
let (time, profit) = (input[0], input[1])
profitFromWork.append((time, profit))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λŸ°μ‹μœΌλ‘œ λ‹΄μœΌμ…¨κ΅°μš”! time, profit이 μ‹€μ œ μ½”λ“œμ—μ„œ μ“°μ΄μ§„μ•Šμ•„μ„œ

profitFromWork.append((input[0], input[1]))
저라면 κ°„κ²°ν•˜κ²Œ μ΄λ ‡κ²Œ ν–ˆμ„ λ“―! 그치만 λ§ˆμΉ΄λ‘œλ‹ˆ 방식이 더 μ•ˆμ „ν•œ 것 κ°™μ•„μš”. κΌΌκΌΌν•œ λ§ˆμΉ΄λ‘œλ‹ˆμ”¨.

Comment on lines +26 to +30
if day + profitFromWork[day].0 <= N {
workTime(day: day + profitFromWork[day].0, profit: profit + profitFromWork[day].1)
}
workTime(day: day + 1, profit: profit)
}
Copy link
Collaborator

@MuchanKim MuchanKim May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μž…λ ₯ κ°’ μ΅œλŒ€μΉ˜κ°€ 15λΌμ„œ μ™„νƒν•˜λ©΄ λ˜κ² λ‹€ 생각을 ν–ˆλŠ”λ° μž¬κ·€λ‘œ 잘 κ΅¬ν˜„ν•˜μ‹  λ“―!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants