[프로그래머스 LV2] 이모티콘

내 솔루션

class DiscountEmoticon {
    static int() order;
    static int() discount={10, 20, 30, 40};
    static int maxPlus;
    static int maxCost;

    public static int() solution(int()() users, int() emoticons) {
        int() answer = new int(2);
        order=new int(emoticons.length);

        dfs(0, users, emoticons);

        answer(0)=maxPlus;
        answer(1)=maxCost;

        return answer;
    }

    private static void dfs(int depth, int()() users, int() emoticons){

        if(depth==emoticons.length){
            int plus=0;
            int cost=0;
            // 할인율대로 이모티콘 플러스, 값 계산
            for(int i=0;i<users.length;i++){
                int totalCost=0;
                for(int j=0;j<emoticons.length;j++){
                    if(users(i)(0)<=order(j))
                        totalCost+=(double)(100-order(j))/100*emoticons(j);
                }
                if(totalCost>=users(i)(1))
                    plus++;
                else
                    cost+=totalCost;
            }
            if(maxPlus<plus) {
                maxPlus = plus;
                maxCost=cost;
            }
            else if(maxPlus==plus){
                if(maxCost<cost)
                    maxCost=cost;
            }
            return;
        }

        for(int i=0;i<4;i++){
            order(depth)=discount(i);
            dfs(depth+1, users, emoticons);
        }

    }

    public static void main(String() args) {
        int()() users={{40, 2900}, {23, 10000}, {11, 5200}, {5, 5900}, {40, 3100}, {27, 9200}, {32, 6900}};
        int() emoticons={1300, 1500, 1600, 4900};

        solution(users, emoticons);

    }

}
  • 이중 순열에서 이모티콘 할인 문구의 시퀀스 찾기
  • 할인율 순으로 이모티콘의 가치를 계산하여 플러스 가입 인원을 구합니다.
    • 이때 등록된 플러스 회원의 수가 같으면 이모티콘 값이 가장 높은 것을 선택하여 저장합니다.