https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
private static final int[] SALE_PERCENT = {10,20,30,40};
public int[] solution(int[][] users, int[] emoticons) {
int[] sale = new int[emoticons.length];
int[] answer = dfs(0,sale,users,emoticons);
return answer;
}
private int[] dfs(int depth,int[] sale, int[][] users,int[] emoticons){
if(depth == emoticons.length){
return cal(sale,users,emoticons);
}
int[] result = new int[] {0,0};
for(int i = 0 ; i < 4; i++){
sale[depth] = SALE_PERCENT[i];
int[] temp = dfs(depth+1,sale,users,emoticons);
if(temp[0] > result[0]){
result = temp;
}else if(temp[0] == result[0] && temp[1] > result[1]){
result = temp;
}
}
return result;
}
private int[] cal(int[] sale, int[][] users,int[] emoticons){
int[] userCost = new int[users.length];
for(int i = 0 ; i < emoticons.length ; i++){
for(int j = 0 ; j < users.length ; j++){
if(sale[i] >= users[j][0]){
userCost[j] += (emoticons[i] * (100 - sale[i])) / 100;
}
}
}
int[] result = new int[2];
for(int i = 0 ; i < users.length ; i++){
if(userCost[i] >= users[i][1]){
result[0]++;
}else{
result[1] += userCost[i];
}
}
return result;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 표현 가능한 이진트리 (JAVA) (0) | 2023.04.02 |
---|---|
프로그래머스 택배 배달과 수거하기(JAVA) (0) | 2023.04.01 |
백준 14501번 퇴사 (JAVA) (0) | 2023.03.30 |
프로그래머스 개인정보 수집 유효기간 (JAVA) (0) | 2023.03.29 |
프로그래머스 혼자서 하는 틱택토 (JAVA) (0) | 2023.03.28 |