Skip to content

Commit

Permalink
[level 2] Title: 멀리 뛰기, Time: 0.17 ms, Memory: 82.7 MB -BaekjoonHub
Browse files Browse the repository at this point in the history
  • Loading branch information
shinjaewon99 committed Sep 28, 2023
1 parent 32f675a commit fc941e0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
62 changes: 62 additions & 0 deletions 프로그래머스/lv2/12914. 멀리 뛰기/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# [level 2] 멀리 뛰기 - 12914

[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12914)

### 성능 요약

메모리: 82.7 MB, 시간: 0.17 ms

### 구분

코딩테스트 연습 > 연습문제

### 채점결과

정확성: 100.0<br/>합계: 100.0 / 100.0

### 문제 설명

<p>효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는<br>
(1칸, 1칸, 1칸, 1칸)<br>
(1칸, 2칸, 1칸)<br>
(1칸, 1칸, 2칸)<br>
(2칸, 1칸, 1칸)<br>
(2칸, 2칸)<br>
의 5가지 방법으로 맨 끝 칸에 도달할 수 있습니다. 멀리뛰기에 사용될 칸의 수 n이 주어질 때, 효진이가 끝에 도달하는 방법이 몇 가지인지 알아내, 여기에 1234567를 나눈 나머지를 리턴하는 함수, solution을 완성하세요. 예를 들어 4가 입력된다면, 5를 return하면 됩니다.</p>

<h5>제한 사항</h5>

<ul>
<li>n은 1 이상, 2000 이하인 정수입니다.</li>
</ul>

<h5>입출력 예</h5>
<table class="table">
<thead><tr>
<th>n</th>
<th>result</th>
</tr>
</thead>
<tbody><tr>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
</tbody>
</table>
<h5>입출력 예 설명</h5>

<p>입출력 예 #1<br>
위에서 설명한 내용과 같습니다.</p>

<p>입출력 예 #2<br>
(2칸, 1칸)<br>
(1칸, 2칸)<br>
(1칸, 1칸, 1칸)<br>
총 3가지 방법으로 멀리 뛸 수 있습니다.</p>


> 출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public long solution(int n) {
long answer = 0;

long[] store = new long[2001];

// 1. n이 1일경우, 2일경우 배열 값 할당
store[1] = 1;
store[2] = 2;


// 2. dp풀이 방식으로 접근
for(int i = 3; i <= n; i++){
store[i] = (store[i - 2] + store[i - 1]) % 1234567;
}

return store[n];
}
}

0 comments on commit fc941e0

Please sign in to comment.