728x90
이항 계수 라는걸 처음봤다..
위와 같이 정의되어있어서, 직접 분모와 분자의 식을 구해서 풀었다.
또한, 재귀함수를 이용했다.
package BAEKJOON;
import java.util.Scanner;
public class NO11050 {
public static int factorial(int a ) {
if( a == 1) {
return 1;
}
return a * factorial(a-1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int answer = factorial(a) / (factorial(b) * factorial(a-b));
System.out.println(answer);
}
}
728x90
'Algorithm & SQL > BAEKJOON' 카테고리의 다른 글
백준 JAVA 1037 약수 (0) | 2022.07.10 |
---|---|
백준 JAVA 1978 소수 찾기 (0) | 2022.07.09 |
백준 JAVA 1934 최소공배수 (0) | 2022.07.08 |
백준 JAVA 11653 소인수분해 (0) | 2022.07.07 |
백준 JAVA 1924 2007년 (0) | 2022.07.07 |
댓글