Skip to content

Commit 7edc9f7

Browse files
committed
[level 0] Title: 구슬을 나누는 경우의 수, Time: 0.11 ms, Memory: 73 MB -BaekjoonHub
1 parent 9e17dbf commit 7edc9f7

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [level 0] 구슬을 나누는 경우의 수 - 120840
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120840)
4+
5+
### 성능 요약
6+
7+
메모리: 73 MB, 시간: 0.11 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩테스트 입문
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 06일 16:59:44
20+
21+
### 문제 설명
22+
23+
<p>머쓱이는 구슬을 친구들에게 나누어주려고 합니다. 구슬은 모두 다르게 생겼습니다. 머쓱이가 갖고 있는 구슬의 개수 <code>balls</code>와 친구들에게 나누어 줄 구슬 개수 <code>share</code>이 매개변수로 주어질 때, <code>balls</code>개의 구슬 중 <code>share</code>개의 구슬을 고르는 가능한 모든 경우의 수를 return 하는 solution 함수를 완성해주세요.</p>
24+
25+
<hr>
26+
27+
<h5>제한사항</h5>
28+
29+
<ul>
30+
<li>1 ≤ <code>balls</code> ≤ 30</li>
31+
<li>1 ≤ <code>share</code> ≤ 30</li>
32+
<li>구슬을 고르는 순서는 고려하지 않습니다.</li>
33+
<li><code>share</code> ≤ <code>balls</code></li>
34+
</ul>
35+
36+
<hr>
37+
38+
<h5>입출력 예</h5>
39+
<table class="table">
40+
<thead><tr>
41+
<th>balls</th>
42+
<th>share</th>
43+
<th>result</th>
44+
</tr>
45+
</thead>
46+
<tbody><tr>
47+
<td>3</td>
48+
<td>2</td>
49+
<td>3</td>
50+
</tr>
51+
<tr>
52+
<td>5</td>
53+
<td>3</td>
54+
<td>10</td>
55+
</tr>
56+
</tbody>
57+
</table>
58+
<hr>
59+
60+
<h5>입출력 예 설명</h5>
61+
62+
<p>입출력 예 #1</p>
63+
64+
<ul>
65+
<li>서로 다른 구슬 3개 중 2개를 고르는 경우의 수는 3입니다.
66+
<img src="https://grepp-programmers.s3.ap-northeast-2.amazonaws.com/files/production/668adf7a-38b1-4112-bbc5-4fab429168c9/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202022-08-01%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%204.15.55.png" title="" alt="스크린샷 2022-08-01 오후 4.15.55.png"></li>
67+
</ul>
68+
69+
<p>입출력 예 #2</p>
70+
71+
<ul>
72+
<li>서로 다른 구슬 5개 중 3개를 고르는 경우의 수는 10입니다.</li>
73+
</ul>
74+
75+
<hr>
76+
77+
<h5>Hint</h5>
78+
79+
<ul>
80+
<li>서로 다른 n개 중 m개를 뽑는 경우의 수 공식은 다음과 같습니다.
81+
<img src="https://grepp-programmers.s3.ap-northeast-2.amazonaws.com/files/production/54c8b2b9-f88c-4a09-8956-7560ff7ea918/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202022-08-01%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%204.37.53.png" title="" alt="스크린샷 2022-08-01 오후 4.37.53.png"></li>
82+
</ul>
83+
84+
<hr>
85+
86+
<p>※ 공지 - 2022년 10월 11일 제한 사항 및 테스트케이스가 수정되었습니다.</p>
87+
88+
89+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public long solution(int balls, int share) {
3+
long answer = 1;
4+
5+
for(int i=0; i<share; i++){
6+
answer *= balls-i;
7+
answer /= i+1;
8+
}
9+
10+
return answer;
11+
}
12+
}

0 commit comments

Comments
 (0)