mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-04 04:02:48 +08:00
feat(ko): add the Korean online edition (#2006)
* feat(ko): add the complete Korean online edition * Use UTF-8 for Python CI output on Windows * Remove print-book promotion from the Korean site * fix(ko): preserve emphasis before Korean particles
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* File: climbing_stairs_dfs.java
|
||||
* Created Time: 2023-06-30
|
||||
* Author: krahets ([email protected])
|
||||
*/
|
||||
|
||||
package chapter_dynamic_programming;
|
||||
|
||||
public class climbing_stairs_dfs {
|
||||
/* 탐색 */
|
||||
public static int dfs(int i) {
|
||||
// dp[1]과 dp[2]는 이미 알고 있으므로 해당 값을 반환한다
|
||||
if (i == 1 || i == 2)
|
||||
return i;
|
||||
// dp[i] = dp[i-1] + dp[i-2]
|
||||
int count = dfs(i - 1) + dfs(i - 2);
|
||||
return count;
|
||||
}
|
||||
|
||||
/* 계단 오르기: 탐색 */
|
||||
public static int climbingStairsDFS(int n) {
|
||||
return dfs(n);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int n = 9;
|
||||
|
||||
int res = climbingStairsDFS(n);
|
||||
System.out.println(String.format("%d개의 계단을 오르는 방법은 총 %d가지이다", n, res));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user