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
- 위클리 챌린지
- 39080
- 너비우선탐색
- 재귀
- 10597
- 좋은 수열
- 순열장난
- 프로그래머스
- 입실 퇴실
- 줄어드는 숫자
- dfs
- BOJ
- 부분 수열의 합
- 완전 탐색
- 백트랙킹
- 복서 정렬하기
- openssl
- BFS
- 코딩테스트
- 그래프
- 문서자동화
- Java
- 백트래킹
- 1174
- ElementTree
- DP
- 위클리 6주차
- 백트렉킹
- 몯느 순열
- 백준
Archives
개발자-H 입니다.
BOJ(18429) - 근손실 (JAVA) 본문
https://www.acmicpc.net/problem/18429
18429번: 근손실
웨이트 트레이닝을 좋아하는 어떤 대학원생은, 현재 3대 운동 중량 500의 괴력을 소유하고 있다. 다만, 하루가 지날 때마다 중량이 K만큼 감소한다. 예를 들어 K=4일 때, 3일이 지나면 중량이 488로
www.acmicpc.net
- 백트래킹 탐색 문제이다.
- 3대 500 이하 일시 바로 탐색을 종료해버리면 된다.
import java.io.*;
import java.util.*;
public class Main {
public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static int N, K;
private static int[] weights;
private static boolean[] visit;
private static int totalMethods;
public static void main(String[] args) throws Exception {
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
weights = new int[N];
visit = new boolean[N];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
weights[i] = Integer.parseInt(st.nextToken());
}
dp(0, 500);
System.out.println(totalMethods);
}
private static void dp(int depth, int weight) {
if (depth > N) {
return;
}
if (weight < 500) {
return;
}
if (depth == N) {
totalMethods += 1;
return;
}
for (int i = 0; i < visit.length; i++) {
if (visit[i]) continue;
visit[i] = true;
dp(depth + 1, weight + weights[i] - K);
visit[i] = false;
}
}
}
'Algorithm > 문제 풀이' 카테고리의 다른 글
BOJ(15686) - 치킨 배달 (JAVA) (0) | 2021.09.29 |
---|---|
BOJ(13301) - 타일 장식물 (JAVA) (0) | 2021.09.28 |
BOJ(10597) - 순열장난 (JAVA) (0) | 2021.09.26 |
BOJ - 모든 순열 (0) | 2021.09.25 |
BOJ - 차이를 최대로 (0) | 2021.09.24 |
Comments