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

solve_fibFrog #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions Lesson 13/FibFrog/FibFrog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import random

def fibo(n):
a, b = 0, 1
fibo_set = set()
fibo_set.add(1)

while b <= n:
a, b = b, a + b
fibo_set.add(b)
return fibo_set

def solution(A):
fibo_set = fibo(len(A))
A.append(1)
dp = [0] * len(A)

for i in range(len(A)):
if A[i] == 1 and i + 1 in fibo_set:
dp[i] = 1
continue

if A[i] == 1 and dp[i] < 1:
min_count = 100001
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인풋값 범위가 혹시나 안 나와있으면 min_count = sys.maxsize

isExist = False
for num in fibo_set:
if i - num < 0 or dp[i - num] < 1:
continue
if A[i - num] == 1:
min_count = min(min_count, dp[i - num])
isExist = True
if isExist:
dp[i] = min_count + 1
return dp[-1] if dp[-1] != 0 else -1


result = solution([1 for _ in range(100000)])
print(result)