THE 1995 DevOps Note
THE 1995 DevOps Note
코딩테스트
백준 - 15649번 N과 M
2025.04.08
import java.util.Scanner;public class Main_15649 {/*문제)자연수 N과 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오.1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열입력)첫째 줄에 자연수 N과 M이 주어진다. (1 ≤ M ≤ N ≤ 8)출력)한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다.수열은 사전 순으로 증가하는 순서로 출력해야 한다. */ static int N,M; static int[]answer; static boolean[] visited;//전체요소 중 각각의 요소가 선택되었는지 여부를 판단 pub..
코딩테스트
SubSet(부분집합)
2025.04.08
public class SubSet { static int N, totalCount; static int[] numbers = {3,5,7,8,9}; static boolean[] selected; public static void main(String[] args) { N = numbers.length; selected = new boolean[N]; subset(0); System.out.println("===> "+totalCount); } private static void subset(int index) { if(index == N) { totalCount++; for(int i=0; i
코딩테스트
Combination(조합)
2025.04.08
import java.util.Arrays;public class Combination { static int N, R, totalCount; static int[] numbers = {3,5,7,8,9},ans; public static void main(String[] args) { N = numbers.length; R = 3; ans = new int[R]; combination(0,0); System.out.println("===> "+totalCount); } private static void combination(int depth, int start) { if(depth == R) { totalCount++; System.out.println(Arrays.toStrin..
코딩테스트
순열(Permutation) 예제
2025.04.08
import java.util.Arrays;public class Permutation1 { public static void permute(int[] arr, int depth, int n) { if (depth == n) { System.out.println(Arrays.toString(arr)); // 순열 출력 System.out.println(); return; } for (int i = depth; i
코딩테스트
순열(Permutation)
2025.04.08
1. 순열의 개념 (Permutation)순열은 서로 다른 n개의 원소 중에서 r개를 순서를 고려하여 나열하는 경우순서가 중요하다.예: [1, 2, 3] 중 2개를 뽑는 경우→ 가능한 순열: [1,2], [1,3], [2,1], [2,3], [3,1], [3,2] 2. 순열 공식nPr = n! / (n - r)!!는 팩토리얼(factorial). 예: 4! = 4 × 3 × 2 × 1 = 24예: 3개 중 2개를 순서 있게 뽑는 경우→ 3P2 = 3! / (3-2)! = 63. Java 코드로 예시예제 1: nPr 계산 (순열 공식으로 계산)public class PermutationFormula { public static void main(String[] args) { int n ..