Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ ex) 1-tgyuuAn
**- ๐Ÿ’ซ Commit**

```
๋ฌธ์ œ ํ•ด๊ฒฐ ๋‚ ์งœ
ex) 2024-10-01
๋ฌธ์ œ๋ฅผ ํ‘ผ ๋‚ ์งœ + ๋ฌธ์ œ ์ด๋ฆ„
ex) 2024-10-01 ๋‘ ์ˆ˜์˜ ํ•ฉ
```

<br>
Expand Down
50 changes: 50 additions & 0 deletions giljihun/DP/[BOJ] 1๋กœ ๋งŒ๋“ค๊ธฐ.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// main.swift
// PS
//
// Created by ๊ธธ์ง€ํ›ˆ on 3/30/25.
//

/* MARK: - NOTE

GOAL => N์„ 1๋กœ ๋งŒ๋“œ๋Š” ์ตœ์†Œ ์—ฐ์‚ฐ ํšŸ์ˆ˜ ์ฐพ๊ธฐ
1. ์ˆซ์ž์—์„œ -1
2. ์ˆซ์ž๊ฐ€ 2๋กœ ๋–จ์–ด์ง€๋ฉด //2
3. ์ˆซ์ž๊ฐ€ 3์œผ๋กœ ๋–จ์–ด์ง€๋ฉด //3

์ž‘์€ ์ˆซ์ž๋ถ€ํ„ฐ 1๋กœ ๋งŒ๋“œ๋Š” ์—ฐ์‚ฐํšŸ์ˆ˜๋ฅผ ๊ตฌํ•ด๊ฐ„๋‹ค.
๊ทธ๋ ‡๊ฒŒ dp๋กœ ํฐ ์ˆซ์ž์˜ ์—ฐ์‚ฐํšŸ์ˆ˜๋ฅผ ๊ตฌํ•  ๋•Œ ๋” ๋นจ๋ฆฌ ๊ตฌํ•˜๋ฉด ๋ ๋“ฏ?

dp[i] = min(dp[i-1], dp[i/2], dp[i/3] + 1
- 2, 3์œผ๋กœ ๋–จ์–ด์ง€๋Š” ๊ฒฝ์šฐ์—๋งŒ.
- ํ•ญ์ƒ 1๋นผ๊ธฐ ์—ฐ์‚ฐ์€ ๊ฐ€๋Šฅ.

*/

// MARK: - CODE
import Foundation

guard let N = Int(readLine() ?? "") else { exit(0) }

if N == 1 {
print(0)
exit(0)
}

var dp = Array(repeating: 0, count: N + 1)
dp[1] = 0

for i in 2...N {
// 1์„ ๋นผ๋Š” ์—ฐ์‚ฐ์€ ํ•ญ์ƒ ๊ฐ€๋Šฅํ•จ
dp[i] = dp[i-1] + 1

if i % 2 == 0 {
dp[i] = min(dp[i], dp[i/2] + 1)
}

if i % 3 == 0 {
dp[i] = min(dp[i], dp[i/3] + 1)
}
}
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
Member Author

Choose a reason for hiding this comment

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

2^31์„ ๋„˜์–ด๊ฐ€๋ฉด ์•ˆ๋˜๋Š”๋ฐ Swift์—์„œ๋Š” 
๋„˜์–ด๊ฐ€๋Š”๊ฑฐ ๊นŒ์ง€ ์ฒ˜๋ฆฌํ•ด๋ฒ„๋ ค์„œ 2^31์ด์ƒ์ด๋ฉด ํ•ด๋‹น ๋ถ€๋ถ„์„ 0์œผ๋กœ ์ฒ˜๋ฆฌ.

์—ฌ๊ธฐ์„œ Swift์—์„œ๋Š” ๋„˜์–ด๊ฐ€๋Š”๊ฑฐ๊นŒ์ง€ ์ฒ˜๋ฆฌํ•œ๋‹ค๋Š”๊ฒŒ ์ฐธ ๋ญ”๊ฐ€ ์™€๋‹ฟ์ง€(?)๊ฐ€ ์•Š๋„ค์š” .. ใ… ใ… 


print(dp[N])
45 changes: 45 additions & 0 deletions giljihun/DP/[BOJ] ๋™์ „ 1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* MARK: - SOLUTION
- ์•„ ์–ด์ผ€ํ’€์ง€?
- dp[i] => i๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜

1. ์ž…๋ ฅ๋ฐ›๊ณ 
2. dp[k+1] ๋ฐฐ์—ด ์ƒ์„ฑ
3. dp[0] = 1 (0์€ ๋นˆ๋ฐฐ์—ด์ด๋ผ๋Š” ์œ ์ผํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ์žˆ์Œ.)
4. ์ ํ™”์‹ ์„ธ์šฐ๊ธฐ
5. ์ถœ๋ฆ์—ญ

*/

import Foundation

guard let input = readLine(),
let n = Int(input.split(separator: " ")[0]),
let k = Int(input.split(separator: " ")[1]) else { exit(0) }
Comment on lines +15 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

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

๊ธธ์€ ์ž…๋ ฅ๋ถ€ํ„ฐ ๋‚จ๋‹ค๋ฆ„.


var numbers: [Int] = []

for _ in 0..<n {
guard let coin = Int(readLine() ?? "") else { exit(0) }

// ๋Ÿฐํƒ€์ž„์—๋Ÿฌ ์žก๊ธฐ1
if coin <= k {
numbers.append(coin)
}
}

var dp = Array(repeating: 0, count: k + 1)
dp[0] = 1

// print(dp)

for num in numbers {
for i in num...k {
dp[i] += dp[i - num]
// ๋Ÿฐํƒ€์ž„์—๋Ÿฌ ์žก๊ธฐ2
if dp[i] >= 2_147_483_648 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ด ์ˆซ์ž๊ฐ€ ๋ญ”๊ฐ€ ํ–ˆ๋”๋‹ˆ Int32 ๋ฒ”์œ„์˜€๊ตฐ์š”! 2^31์„ ํ‘œํ˜„ํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•๋„ ๊ณต์œ ๋“œ๋ฆฝ๋‹ˆ๋‹ค~

// Int32 ๋ฒ”์œ„์— ๋Œ€ํ•œ ๋‹ค์–‘ํ•œ ํ‘œํ˜„๋“ค

// Int32 ๋‚ด์žฅ ์ƒ์ˆ˜
let maxInt = Int(Int32.max) + 1  // 2,147,483,648

// ๋น„ํŠธ์‹œํ”„ํŠธ
let intMax = 1 << 31. // 2,147,483,648

Copy link
Collaborator

Choose a reason for hiding this comment

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

์˜ค ์ข‹๋„ค์š” ๐Ÿ‘ ํ›จ์”ฌ๊ฐ„๋‹จํ•˜๊ฒŒ ์ ์„ ์ˆ˜ ์žˆ๊ตฐ์š”

dp[i] = 0
}
Comment on lines +38 to +41
Copy link
Collaborator

@bishoe01 bishoe01 Apr 13, 2025

Choose a reason for hiding this comment

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

์ง„์งœ ์•„๋ฌด๋ฆฌ๋ด๋„ ๋งž๋Š”๊ฑฐ๊ฐ™์€๋ฐ, ๋Ÿฐํƒ€์ž„์—๋Ÿฌ ๋ฌดํ•œ์œผ๋กœ ๋– ์„œ ๊ธธ์„ ์ƒ๋‹˜ ์ด ๋ถ€๋ถ„ ์ฐธ๊ณ ํ•ด์„œ ํ†ต๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ‘
แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2025-04-13 แ„‹แ…ฉแ„’แ…ฎ 2 23 49

๋ฐฑ์ค€์ง„์งœ ๊ฐœ์—ด๋ฐ›๋„ค์š” ..

Copy link
Member Author

Choose a reason for hiding this comment

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

ใ…‹ใ…‹ใ…‹ใ…‹๋Šช์— ์˜ค์…จ์—ˆ๊ตฐ์š”!!
์•„์ง๊นŒ์ง€ ์ •ํ™•ํ•˜๊ฒŒ ์›์ธ์„ ๋ชจ๋ฅด๊ฒ ๋„ค์š” ์œ„์—๋„ ์ ์—ˆ์ง€๋งŒ ์•„๋ž˜ ๋‚ด์šฉ์— ๋Œ€ํ•œ ํ•ด๋‹ต์„ ์•„์ง ์–ป์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ˜น์‹œ ๋ฐฑ์ค€ swift ์ปดํŒŒ์ผ๋Ÿฌ์—์„  Int32๋กœ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๋Š”๊ฑด๊ฐ€์š”?
์ด ๋ถ€๋ถ„ ์ž˜ ์ดํ•ดํ•˜์‹  ๋ถ„ ๋„์›€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bishoe01 ์•„๋ž˜ ์ฝ”๋ฉ˜ํŠธ๊ฐ€ ์•ˆ๋‹ฌ๋ ค์„œ ์—ฌ๊ธฐ ๋‹ฌ๊ฒ ์”€๋‹ค !

2๋ฒˆ๊ณผ 3๋ฒˆ์„ ์–ด๋–ป๊ฒŒ ์ค‘๋ณต์ฒ˜๋ฆฌ๋ฅผ ๋นผ์ค„๊ฒƒ์ด๋ƒ๋กœ ๊ณ„์† ์ฐพ์œผ๋ คํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š”.
๊ฒฐ๊ตญ ๋™์ „๋‹จ์œ„๋กœ ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ ค์ฃผ๋ฉด ์ž‘์€์• ๋ถ€ํ„ฐ ๋“ค์–ด๊ฐ€๋Š”๊ฑฐ๋กœ ๊ฐ•์ œํ•  ์ˆ˜ ์žˆ๋”๋ผ๊ตฌ์š”.

์ €๋„ ์ด ๋ถ€๋ถ„์ด ๋˜๊ฒŒ ํ—ท๊ฐˆ๋ ธ๊ณ , ๊ทธ๋ž˜์„œ ํ‘œ๋ฅผ ๊ทธ๋ฆฌ๋ฉด์„œ ์ž‘์€ ๋™์ „ ๋‹จ์œ„๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์Œ“์ด๋Š”๊ฑธ ๋ณด๋‹ˆ ๋‹น์—ฐํ•˜๊ฒŒ๋„ dp๋กœ ํ‘ธ๋Š” ์ž…์žฅ์—์„  ์ƒ๊ฐํ•  ๋ถ€๋ถ„์ด ์•„๋‹ˆ๋”๋ผ๊ตฌ์š”!

๊ทธ๋ฆฌ๊ณ  ์ฒซ๋ฒˆ์งธ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ๋„˜ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ํ•˜์…จ๋„ค์œ  ใ…Žใ…Ž

}
}

print(dp[k])
3 changes: 2 additions & 1 deletion giljihun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2024.10.01 | ๊ตฌํ˜„ | [์ถ”์–ต ์ ์ˆ˜](https://school.programmers.co.kr/learn/courses/30/lessons/176963)|https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/35|
| 1์ฐจ์‹œ | 2025.03.30 | DP | [1๋กœ ๋งŒ๋“ค๊ธฐ](https://www.acmicpc.net/problem/1463)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/4|
| 2์ฐจ์‹œ | 2025.04.08 | DP | [๋™์ „ 1](https://www.acmicpc.net/problem/2293)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/8|
---