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

Create 2024-03-13-level2-14.md #104

Closed
wants to merge 1 commit into from
Closed
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
53 changes: 53 additions & 0 deletions _posts/2024-03-13-level2-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
layout: single
title: "프로그래머스 LV2 - 멀리 뛰기"
categories: CodingTest
tag: [LV2, 프로그래머스, 코딩테스트, ONE MORE TIME]
author_profile: false
sidebar:
nav: "counts"
---

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

## 내 풀이
```python
def solution(n):
left = n
right = 0
answer = 0
while left >= right:
bunza = 1
bunmo = 1
if right == 0:
answer += 1
elif left == right:
answer += 1
else:
for i in range(right):
bunza *= left-i
bunmo *= right-i
answer += bunza // bunmo
left -= 1
right += 1
return answer % 1234567
```

## 다른 풀이
```python
def solution(n):
if n<3:
return n
d=[0]*(n+1)
d[1]=1
d[2]=2
for i in range(3,n+1):
d[i]=d[i-1]+d[i-2]
return d[n]%1234567
```

### 풀이 해석
- 계단을 1,2칸만 올라갈 수 있으므로 3칸을 오를 때는 1,2칸을 오르는 경우의 수를 합해주면 되고, 점화식으로 나타내면 $f(n) = f(n-1) + f(n-2)$ 피보나치 수열을 구할 때와 같다

### 배울점
- 피포나치 수열의 이용
Loading