-
[Softeer] 택배 마스터 광우 (lv.3)ALGORITHM/SWEXPERT|SOFTEER 2021. 11. 2. 22:45
https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=581
2021
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import java.util.*;import java.io.*;public class Main {public static int N, M, K, answer;public static int[] arr;public static boolean[] vtd;public static void solve(int[] parcel) {int idx = 0;int total = 0;for(int i = 0; i < K; i++) {int sum = 0;for(int j = idx; ;j++) {if(sum + parcel[j%N] > M) {idx = j;break;}else sum += parcel[j%N];}total += sum;}answer = Math.min(answer, total);}public static void comb(int cnt, int[] p) {if(cnt == N) {solve(p);return;}for(int i = 0; i < N; i++) {if(!vtd[i]) {vtd[i] = true;p[cnt] = arr[i];comb(cnt+1, p);vtd[i] = false;}}}public static void main(String[] args) throws IOException {BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));StringTokenizer st = new StringTokenizer(bf.readLine());N = Integer.parseInt(st.nextToken());M = Integer.parseInt(st.nextToken());K = Integer.parseInt(st.nextToken());answer = 987654321;arr = new int[N];vtd = new boolean[N];st = new StringTokenizer(bf.readLine());for(int i = 0; i < N; i++) {arr[i] = Integer.parseInt(st.nextToken());}int[] p = new int[N];comb(0, p);System.out.println(answer);}}cs 'ALGORITHM > SWEXPERT|SOFTEER' 카테고리의 다른 글
[Softeer] 전광판 (lv.2) (0) 2022.01.16 [Softeer] 비밀메뉴 (lv.2) (0) 2022.01.16 [Softeer] 스마트 물류 (lv.3) (0) 2021.11.02 [Softeer] 동계 테스트 시점 예측 (lv.3) (0) 2021.11.02 [Softeer] GBC (lv.2) (0) 2021.11.02