-
Notifications
You must be signed in to change notification settings - Fork 1
10-csecaujunseo #38
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
10-csecaujunseo #38
Changes from all commits
6ad7867
c14c0ab
299e9ec
eb45120
ffa18ab
f77f345
21592df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #define _CRT_SECURE_NO_WARNINGS | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #define MIN(a,b) ((a) < (b) ? (a) : (b)) | ||
| #define MAX 1000001 | ||
|
|
||
|
|
||
| int main() { | ||
|
|
||
| int N = 0; | ||
| scanf("%d", &N); | ||
|
|
||
| int* dp = (int*)malloc(sizeof(int) * MAX); | ||
|
|
||
| if (dp == NULL) { | ||
| printf("λ©λͺ¨λ¦¬ ν λΉ μ€ν¨!\n"); | ||
| return 1; | ||
| } | ||
|
Comment on lines
+15
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄ μ½λλ λμ λ©λͺ¨λ¦¬ ν λΉ μ€ν¨μ λλΉνκΈ° μν΄μ μμ±νμ κ² κ°μλ°, μ΄ κ²½μ°μλ ν λΉ ν¬κΈ°κ° κ³ μ λ μμ(MAX)μ΄κ³ ν¬κΈ°λ λΉκ΅μ μμμ μΌλ°μ μΈ νκ²½μμλ ν λΉ μ€ν¨κ° λ°μν κ°λ₯μ±μ΄ κ±°μ μλ€κ³ λ΄λ λ©λλ€. λ°±μ€μμλ μ₯κ°ν΄μ λ©λλ©. μ§μλ 무방ν κ² κ°λ€μ. |
||
|
|
||
| dp[1] = 0; | ||
|
|
||
| for (int i = 2; i < N + 1; 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); | ||
| } | ||
| } | ||
|
|
||
| printf("%d", dp[N]); | ||
|
|
||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mallocμ λμ λ©λͺ¨λ¦¬ ν λΉμ μ¬μ©νλ ν¨μμΈλ°, MAX κ°μ μμλ‘ μ ν΄λκ³ μ΄λ₯Ό κΈ°λ°μΌλ‘ ν λΉνλ κ²μ μ¬μ€μ μ μ λ©λͺ¨λ¦¬ ν λΉκ³Ό λ€λ₯Ό λ° μμ΄ λ³΄μ΄λ€μ..! μ μ λ©λͺ¨λ¦¬ ν λΉμΌλ‘λ μΆ©λΆν ν΄κ²°ν μ μλ λ¬Έμ λΌμ λ€μκ³Ό κ°μ΄ μμ νλ©΄ ν¨μ¬ κ°λ¨ν μ½λκ° λ κ² κ°μ΅λλ€.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
첨μΈνμλ©΄, ν¨μ λ΄μμ ν° μ¬μ΄μ¦μ λ°°μ΄μ μ μΈνκ² λ κ²½μ° Stack λ©λͺ¨λ¦¬ μ΄κ³Όκ° λ°μν μ μμ΅λλ€. κ³ μ λ ν° ν¬κΈ°μ λ°°μ΄μ μ μΈνκ³ μΆμΌλ©΄ μ μ λ³μλ‘ λλ κ² μ’μ΅λλ€ :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ€ν κ·Έλ λ€μ!
μμ¦ λ¬΄μ‘°κ±΄μ μΌλ‘ μ μ ν λΉμ νκ³ μλ λ°, μ’ λ μ½λλ₯Ό μΈ λ μκ°νκ³ , μν©μ λ§κ² μ¨λ΄μΌ ν κ±° κ°μ΄λ€!