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

16-wkdghdwns199 #65

Merged
merged 3 commits into from
Mar 27, 2024
Merged

16-wkdghdwns199 #65

merged 3 commits into from
Mar 27, 2024

Conversation

wkdghdwns199
Copy link
Collaborator

πŸ”— 문제 링크

https://www.acmicpc.net/problem/11050

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„ - factorial ν•¨μˆ˜λΌλŠ” 게 μžˆλ„€..?

✨ μˆ˜λ„ μ½”λ“œ

정말 μ‰¬μš΄ 문제인데, λ‹€λ₯Έ 풀이도 μžˆμ–΄μ„œ ν’€μ–΄λ΄€μŠ΅λ‹ˆλ‹€!

μš°μ„  이항 κ³„μˆ˜λž€ 이항식을 이항 μ •λ¦¬λ‘œ μ „κ°œν–ˆμ„ λ•Œ 각 ν•­μ˜ κ³„μˆ˜μ΄λ©°, 주어진 크기의 (μˆœμ„œ μ—†λŠ”) μ‘°ν•©μ˜ κ°€μ§“μˆ˜ 이닀.
κ·Έλž˜μ„œ 쑰합을 κ³„μ‚°ν•˜λ©΄ λ˜λŠ” 문제인데, 식은
nCk = n! // (k! * (n-k)!) μž…λ‹ˆλ‹€.

κ·ΈλŸ¬λ―€λ‘œ νŒ©ν† λ¦¬μ–Όμ„ κ³„μ‚°ν•˜λŠ” ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄μ„œ νŒ©ν† λ¦¬μ–Ό 계산 ν›„, μ‘°ν•© μ‹μœΌλ‘œ 계산을 ν•΄μ„œ 좜λ ₯을 ν•˜λ©΄ λœλ‹€.

from sys import stdin

def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1)

n, k = map(int, stdin.readline().split())
print(factorial(n) // (factorial(k) * factorial(n - k)))

파이썬 factorial math ν•¨μˆ˜κ°€ μžˆλ„€μš”. 더 κ°„λ‹¨ν•˜κ²Œ μž‘μ„±ν•΄λ΄€μŠ΅λ‹ˆλ‹€.

import sys, math
input = sys.stdin.readline
N,K = map(int, input().split())
print(math.factorial(N) // (math.factorial(K) * math.factorial(N-K)))

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@alstjr7437
Copy link
Member

μ˜ˆμ „μ— ν‘Ό 문제인데
μ €λŠ” 두가지 λ°©λ²•μœΌλ‘œ ν’€μ—ˆμ—ˆλ„€μš”!!

def fibo(n, k):
    if k == 0 or n == k:
        return 1
    return fibo(n-1, k) + fibo(n-1, k-1)

print(fibo(n,k))

def fibo2(n):
    if n == 0 :
        return 1
    return n * fibo2(n-1)

print(fibo2(n)// (fibo2(n-k) * fibo2(k)))

Copy link
Member

@fnzksxl fnzksxl left a comment

Choose a reason for hiding this comment

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

μ•„ μž¬κ·€ κ΅­λ£° λ¬Έμ œκ΅°μš” !
이 문제 처음 ν’€ λ•Œ nCk μ–΄λ–»κ²Œ λ°”κΎΈλŠ”μ§€ κΈ°μ–΅ μ•ˆ λ‚˜μ„œ 곡식 검색해본 기얡이 λ‚˜λ„€μš”.. 그런데 저도 νŒŒμ΄μ¬μ—μ„œ math 라이브러리λ₯Ό κΊΌλ‚΄λ³Έ 적이 μ—†μ–΄μ„œ 이게 κ΅¬ν˜„μ΄ λ˜μ–΄μžˆλŠ”μ§€λŠ” 처음 μ•Œμ•˜λ„€μš”

import sys

input = sys.stdin.readline

def func(n):
    if n == 0:
        return 1
    return n * func(n-1)

N, K = map(int, input().split())
print(func(N) // (func(K) * factorial(N-K)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants