Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7-kangrae-jo #24

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions kangrae-jo/DP/7-kangrae-jo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
int N;
cin >> N;

vector<int> dp(N + 1, 0);
dp[1] = 0;
dp[2] = 1;
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-1]밖에 ν™•μΈμ•ˆν•˜λ‹ˆ μ΄ˆκΈ°ν™”λŠ” 2κΉŒμ§€λ©΄ μΆ©λΆ„ν•˜λ„€μš”


for (int i = 3; i <= N; i++) {
dp[i] = dp[i-1] + 1;
if (i % 3 == 0) dp[i] = min(dp[i], dp[i / 3]+1);
if (i % 2 == 0) dp[i] = min(dp[i], dp[i / 2]+1);
}
Comment on lines +15 to +19
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]λ₯Ό setν•˜κ²Œ λ˜λ‹ˆ 미리 μ§€μ •ν•˜κ³  더 μž‘μ€ κ°’μœΌλ‘œ λΆ„λ₯˜ν•˜λ©΄ 이런 μ½”λ“œκ°€ λ‚˜μ˜¬ 수 μžˆλ„€μš”

cout << dp[N];

return 0;
}
11 changes: 6 additions & 5 deletions kangrae-jo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2024.09.28 | DP | [연속합](https://www.acmicpc.net/problem/1912)| [#2]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/2|
| 2μ°¨μ‹œ | 2024.10.01 | BruteForce | [카펫](https://school.programmers.co.kr/learn/courses/30/lessons/42842)| [#6]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/6|
| 3μ°¨μ‹œ | 2024.10.05 | BFS | [ν† λ§ˆν† ](https://www.acmicpc.net/problem/7576)| [#10]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/10|
| 4μ°¨μ‹œ | 2024.10.05 | BFS | [μ•„μ΄ν…œ 쀍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694)|[#12]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/12|
| 1μ°¨μ‹œ | 2024.09.28 | DP | [연속합](https://www.acmicpc.net/problem/1912)| [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/2)|
| 2μ°¨μ‹œ | 2024.10.01 | BruteForce | [카펫](https://school.programmers.co.kr/learn/courses/30/lessons/42842)| [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/6)|
| 3μ°¨μ‹œ | 2024.10.05 | BFS | [ν† λ§ˆν† ](https://www.acmicpc.net/problem/7576)| [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/10)|
| 4μ°¨μ‹œ | 2024.10.05 | BFS | [μ•„μ΄ν…œ 쀍기](https://school.programmers.co.kr/learn/courses/30/lessons/87694)|[#12](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/12)|
| 5μ°¨μ‹œ | 2024.11.02 | DP | [경쟁 λ°°νƒ€μ˜ 원리](https://level.goorm.io/exam/162070/%EA%B2%BD%EC%9F%81-%EB%B0%B0%ED%83%80%EC%9D%98-%EC%9B%90%EB%A6%AC/quiz/1)|[#18](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/18)|
| 6μ°¨μ‹œ | 2024.11.05 | Greedy | [단속카메라](https://school.programmers.co.kr/learn/courses/30/lessons/42884)| [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/21)|
| 5μ°¨μ‹œ | 2024.11.02 | DP | [경쟁 λ°°νƒ€μ˜ 원리](https://level.goorm.io/exam/162070/%EA%B2%BD%EC%9F%81-%EB%B0%B0%ED%83%80%EC%9D%98-%EC%9B%90%EB%A6%AC/quiz/1)|[#18]https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/18|
| 7μ°¨μ‹œ | 2024.11.09 | DP | [1둜 λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/1463)|[#12](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/24|)

---