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 |
Tags
- Java
- 입실 퇴실
- 순열장난
- BOJ
- 몯느 순열
- 그래프
- 10597
- 1174
- 너비우선탐색
- 코딩테스트
- DP
- 백준
- 완전 탐색
- ElementTree
- 부분 수열의 합
- BFS
- 백트랙킹
- 재귀
- 줄어드는 숫자
- 39080
- 위클리 6주차
- openssl
- 복서 정렬하기
- 프로그래머스
- dfs
- 문서자동화
- 백트래킹
- 위클리 챌린지
- 백트렉킹
- 좋은 수열
Archives
개발자-H 입니다.
BOJ - 선발 명단 본문
https://www.acmicpc.net/problem/3980
3980번: 선발 명단
각각의 테스트 케이스에 대해서, 모든 포지션의 선수를 채웠을 때, 능력치의 합의 최댓값을 한 줄에 하나씩 출력한다. 항상 하나 이상의 올바른 라인업을 만들 수 있다.
www.acmicpc.net
- 백트래킹을 활용한 완전 탐색 문제이다.
- 주어진 포지션의 개수와 플레이어 포지션 별 능력을 활용하여 완전 탐색 후 최대 값을 구하면 된다.
import java.io.*;
import java.util.*;
public class Main {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static int[][] abilities;
private static int maximumAbility;
private static boolean[] positions;
public static void main(String[] args) throws IOException {
int C = Integer.parseInt(br.readLine());
while (C-- > 0) {
//초기화
abilities = new int[11][11];
positions = new boolean[11];
maximumAbility = 0;
for (int i = 0; i < 11; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < 11; j++) {
abilities[i][j] = Integer.parseInt(st.nextToken());
}
}
dp(0, 0, 0);
System.out.println(maximumAbility);
}
}
private static void dp(int depth, int player, int ability) {
if (depth == 11) {
if (!isPositionValid()) return;
maximumAbility = Math.max(maximumAbility, ability);
return;
}
for (int i = 0; i < 11; i++) {
if (abilities[player][i] == 0) continue;
if (positions[i]) continue;
positions[i] = true;
ability += abilities[player][i];
dp(depth + 1, player + 1, ability);
positions[i] = false;
ability -= abilities[player][i];
}
}
private static boolean isPositionValid() {
for (int i = 0; i < positions.length; i++) {
if (!positions[i]) return false;
}
return true;
}
}
'Algorithm > 문제 풀이' 카테고리의 다른 글
BOJ - 차이를 최대로 (0) | 2021.09.24 |
---|---|
BOJ - 좋은 수열 (0) | 2021.09.23 |
BOJ - 암호 만들기 (0) | 2021.09.22 |
BOJ - 색종이 붙이기 (0) | 2021.09.21 |
BOJ - 연산자 끼워넣기 (0) | 2021.09.20 |
Comments