일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- counter
- lv4
- 파이썬
- 코딩
- Stack
- 연습문제
- BFS
- mysql
- Queue
- 프로그래머스
- lambda
- time complexity
- level4
- 시간복잡도
- programmers
- sql
- itertools
- 코테
- 코딩테스트
- import re
- python
- 완전탐색
- 데이터분석
- join
- coding
- coding test
- Level2
- 조합
- CodingTest
- collections
- Today
- Total
ror_coding
[Programmers] 멀리 뛰기 - 12914 본문
728x90
math.comb()를 이용해서 구하는 코드.
Question
효진이는 멀리 뛰기를 연습하고 있습니다. 효진이는 한번에 1칸, 또는 2칸을 뛸 수 있습니다. 칸이 총 4개 있을 때, 효진이는
(1칸, 1칸, 1칸, 1칸)
(1칸, 2칸, 1칸)
(1칸, 1칸, 2칸)
(2칸, 1칸, 1칸)
(2칸, 2칸)
의 5가지 방법으로 맨 끝 칸에 도달할 수 있습니다. 멀리뛰기에 사용될 칸의 수 n이 주어질 때, 효진이가 끝에 도달하는 방법이 몇 가지인지 알아내, 여기에 1234567를 나눈 나머지를 리턴하는 함수, solution을 완성하세요. 예를 들어 4가 입력된다면, 5를 return하면 됩니다.
Code
import math
def solution(n):
answer = 0
twos = n//2
start = twos
if n%2==1 : start += 1
for i in range(start, n+1):
answer += math.comb(i,twos)
twos -= 1
return answer % 1234567
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/029.gif)
now me
On my github
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmers] 연속 부분 수열 합의 개수 - 131701 (0) | 2024.11.01 |
---|---|
[Programmers] 예상 대진표 - 12985 (0) | 2024.10.31 |
[Programmers] 점프와 순간 이동 - 12980 (0) | 2024.10.28 |
[Programmers] 올바른 괄호 - 12909, 짝지어 제거하기 - 12973 (0) | 2024.10.28 |
[Programmers] 신고 결과 받기 - 92334 (0) | 2024.10.28 |