-
Notifications
You must be signed in to change notification settings - Fork 2
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
40-Dolchae #154
Conversation
There was a problem hiding this 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 ์ต์๋น์ฉ ๊ตฌํ๊ธฐ ์๊ฑฐ ๊ธฐ์ด์ ์ธ ๋ค์ต์คํธ๋ผ ๋ฌธ์ ์ด๋ ํ ๋ฒ ๊ณต๋ถํด๋ณด๊ณ ํ์ด๋ด
์๋ค ๐ฅ๐ฅ
There was a problem hiding this 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 | ||
|
There was a problem hiding this comment.
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)))
๐ ๋ฌธ์ ๋งํฌ
2407 ์กฐํฉ
โ๏ธ ์์๋ ์๊ฐ
30๋ถ
โจ ์๋ ์ฝ๋
๋ฌธ์
n๊ณผ m์ด ์ฃผ์ด์ง ๋ nCm์ ์ถ๋ ฅํ๋ ๋ฌธ์ ์ด๋ค.
์กฐํฉ ๊ณต์
์ ์ฒด์ฝ๋&์ค๋ช
n๊ณผ m์ ์ ๋ ฅ๋ฐ๊ณ , ํฉํ ๋ฆฌ์ผ์ ๊ณ์ฐํ๋ ํจ์๋ฅผ ๊ตฌํํ๋ค. ๊ทธ๋ฆฌ๊ณ ์กฐํฉ์ ๊ณต์์ ๋ฐ๋ผ factorialํจ์๋ฅผ ์ด์ฉํด ๊ฐ์ ํ๋ฆฐํธํด์ค๋ค.
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
๋ฆ์ด์ ์ฃ์กํฉ๋๋ค...๐ฅฒ