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

40-Dolchae #154

Merged
merged 2 commits into from
Apr 30, 2024
Merged

40-Dolchae #154

merged 2 commits into from
Apr 30, 2024

Conversation

Dolchae
Copy link
Collaborator

@Dolchae Dolchae commented Apr 2, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

2407 ์กฐํ•ฉ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

30๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ

n๊ณผ m์ด ์ฃผ์–ด์งˆ ๋•Œ nCm์„ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

์กฐํ•ฉ ๊ณต์‹

image

์ „์ฒด์ฝ”๋“œ&์„ค๋ช…

import sys

input = sys.stdin.readline

n,m = map(int,input().split())

def factorial(num):
    result = 1
    for i in range(1,num+1):
        result *= i
    return result
    
print(factorial(n)//(factorial(n-m)*factorial(m)))

n๊ณผ m์„ ์ž…๋ ฅ๋ฐ›๊ณ , ํŒฉํ† ๋ฆฌ์–ผ์„ ๊ณ„์‚ฐํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์กฐํ•ฉ์˜ ๊ณต์‹์— ๋”ฐ๋ผ factorialํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ๊ฐ’์„ ํ”„๋ฆฐํŠธํ•ด์ค€๋‹ค.


๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

๋Šฆ์–ด์„œ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค...๐Ÿฅฒ

Copy link
Collaborator

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

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

์—†๋Š” ๊ฒŒ ์—†๋Š” ํŒŒ์ด์ฌ;; ์ด๊ฒƒ๋งˆ์ €๋„ math ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ์กฐํ•ฉ ํ•จ์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋„ค์š”

from math import comb
n, m = map(int, input().split())
print(comb(n, m))

์ด์ œ ๋ณต์žกํ•œ ๋ฌธ์ œ ํ•œ ๋ฒˆ ํ’€์–ด๋ณผ๊นŒ์š”? ๋งˆ์นจ ์ตœ๊ทผ์— heap๋„ ์จ๋ดค๊ฒ ๋‹ค, DFS/BFS๋„ ์—ฌ๋Ÿฌ ๋ฒˆ ํ’€์–ด๋ดค์œผ๋‹ˆ "๋‹ค์ต์ŠคํŠธ๋ผ ์ตœ๋‹จ๊ฒฝ๋กœ" ๋ฌธ์ œ ํ•œ ๋ฒˆ ํ’€์–ด๋ด…์‹œ๋‹ค :)
1916 ์ตœ์†Œ๋น„์šฉ ๊ตฌํ•˜๊ธฐ ์š”๊ฑฐ ๊ธฐ์ดˆ์ ์ธ ๋‹ค์ต์ŠคํŠธ๋ผ ๋ฌธ์ œ์ด๋‹ˆ ํ•œ ๋ฒˆ ๊ณต๋ถ€ํ•ด๋ณด๊ณ  ํ’€์–ด๋ด…์‹œ๋‹ค ๐Ÿ”ฅ๐Ÿ”ฅ

Copy link
Member

@xxubin04 xxubin04 left a comment

Choose a reason for hiding this comment

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

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!
์ €๋„ factorial ํ•จ์ˆ˜๋กœ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” //์ด ์•„๋‹Œ /๋กœ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ–ˆ์—ˆ๋Š”๋ฐ, ๊ฒฐ๊ณผ๊ฐ’์ด ์•„์ฃผ ํด ๊ฒฝ์šฐ์—๋Š” ์˜ค์ฐจ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•˜๋„ค์š”..๐Ÿ˜ฆ ๊ทธ๋ž˜์„œ fractions ๋ชจ๋“ˆ๋กœ ์ œ์ถœํ–ˆ๋”๋‹ˆ ํ†ต๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค~ fractions ๋ชจ๋“ˆ์ด ์œ ๋ฆฌ์ˆ˜๋ฅผ ์ข€ ๋” ์ •ํ™•ํ•˜๊ฒŒ ๋‹ค๋ฃฌ๋‹ค๊ณ  ํ•˜๋„ค์š”.

from itertools import combinations
from fractions import Fraction

input = open(0).readline 
n, m = map(int, input().split())

def factorial(a, result):
    if a >= 2:
        result *= a
        return factorial(a-1, result)
    else:
        return result
        
print(Fraction(factorial(n, 1), (factorial(n-m, 1)*factorial(m, 1))))

for i in range(1,num+1):
result *= i
return result

Copy link
Member

Choose a reason for hiding this comment

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

python math ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ๋Š” factorial ํ•จ์ˆ˜๋„ ์ง€์›ํ•ด์ค๋‹ˆ๋‹ค!

from math import factorial

n, m = map(int,input().split())

print(factorial(n)//(factorial(n-m)*factorial(m)))

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.

4 participants