Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 자바스크립트
- Deep Dive
- 딥다이브
- oauth
- concurrency limit
- 코멘토 #코멘토실무PT #실무PT후기 #실무강의 #리액트강의 #웹프로그래밍 #react #웹개발실무
- this
- 우아한 테크코스
- invalid_grant
- redis
- bucket4j
- 음악 url 파일 다운로드
- 타입스크립트
- api 요청 수 제한
- 파일 url
- 프론트엔드
- compateto
- AWS
- 검색
- NestJS
- 유효시간 설정 url
- Dev-Matching
- api 비동기처리
- 프리코스
- 프로그래머스
- TypeORM
- 프론트엔드 과제
- 모던 자바스크립트
- 스프링부트
- 우아한테크코스
Archives
- Today
- Total
개발 알다가도 모르겠네요
삼성 SDS 대학생 알고리즘 특강 5일차 - 조합론 본문
728x90
1256: 사전
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, M, K;
static int[][] dp = new int[201][201];
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
if (K > combination(N + M, M)) {
System.out.println("-1");
} else {
}
}
public static void query(int n, int m, int k) {
// 단어 끝에 도달
if (n + m == 0) {
return;
}
// z만 남은경우
else if (n == 0) {
sb.append('z');
query(n, m - 1, k);
}
// a만 남은경우
else if (m == 0) {
sb.append('a');
query(n - 1, m, k);
}
// a, z 둘다 남은 경우 a를 고를 때 조합 수를 보고 판단
else {
int leftCount = combination(n + m - 1, m);
if (leftCount >= k) {
sb.append('a');
query(n - 1, m, k);
} else {
sb.append('z');
query(n, m - 1, k - leftCount);
}
}
}
public static int combination(int n, int r) {
if (n == r || r == 0) {
return 1;
} else if (dp[n][r] != 0) {
return dp[n][r];
} else {
return dp[n][r] = Math.min((int) 1e9, combination(n - 1, r - 1) + combination(n - 1, r));
}
}
}
1722: 순열의 순서
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N;
static int[] nums;
static long[] fact = new long[21];
static long[][] dp;
static boolean[] visited;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
fact[0] = 1;
for (int i = 1; i <= 20; ++i) {
fact[i] = fact[i - 1] * i;
}
N = Integer.parseInt(br.readLine());
visited = new boolean[N + 1];
StringTokenizer st = new StringTokenizer(br.readLine());
int command = Integer.parseInt(st.nextToken());
if (command == 1) {
long target = Long.parseLong(st.nextToken());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) {
for (int j = 1; j <= N; j++) {
if (visited[j] == true) {
continue;
}
if (target > fact[N - i - 1]) {
target -= fact[N - i - 1];
} else {
sb.append(j);
sb.append(" ");
visited[j] = true;
break;
}
}
}
System.out.println(sb.toString());
} else if (command == 2) {
nums = new int[N];
for (int i = 0; i < N; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
long result = 0;
for (int i = 0; i < N; i++) {
for (int j = 1; j < nums[i]; j++) {
if (visited[j] == false) {
result += fact[N - i - 1];
}
}
visited[nums[i]] = true;
}
System.out.println(result + 1);
}
}
}
'학습일지 > 삼성 SDS 알고리즘 특강' 카테고리의 다른 글
삼성 SDS 대학생 알고리즘 특강 7일차 - 그래프 (0) | 2022.07.26 |
---|---|
삼성 SDS 대학생 알고리즘 특강 6일차 - 그래프 (0) | 2022.07.25 |
삼성 SDS 대학생 알고리즘 특강 4일차 - 트라이 트리, 정수론 (0) | 2022.07.21 |
삼성 SDS 대학생 알고리즘 특강 3일차 - 자료구조 (0) | 2022.07.20 |
삼성 SDS 대학생 알고리즘 특강 2일차 - 정렬 (0) | 2022.07.19 |