|
| 1 | +```java |
| 2 | +import java.util.*; |
| 3 | +class Solution { |
| 4 | + private static List<int[]> combs; |
| 5 | + private static int[] comb; |
| 6 | + private static int[] coupons = new int[]{10, 20, 30, 40}; |
| 7 | + private static int NOfE; |
| 8 | + public int[] solution(int[][] users, int[] emoticons) { |
| 9 | + NOfE = emoticons.length; |
| 10 | + combs = new LinkedList<int[]>(); |
| 11 | + comb = new int[NOfE]; |
| 12 | + var answer1 = 0; |
| 13 | + var answer2 = 0; |
| 14 | + //# 이모티콘 부분집합 for ex. 10, 20, 30, 30, 30... 4^7 |
| 15 | + getComb(); |
| 16 | + for(int[] combE : combs){ |
| 17 | + //System.out.println(Arrays.toString(combE)); |
| 18 | + int[] candidates = new int[2]; |
| 19 | + //## 유저 for문 |
| 20 | + int[] prices = new int[NOfE]; |
| 21 | + for(int i = 0; i<prices.length; i++) |
| 22 | + prices[i] = emoticons[i]/100 * (100 - combE[i]); |
| 23 | + outer: |
| 24 | + for(int[] u: users){ |
| 25 | + //System.out.println(Arrays.toString(u)); |
| 26 | + int uPercent = u[0]; |
| 27 | + int uPrice = u[1]; |
| 28 | + int uTotal = 0; |
| 29 | + for(int i = 0; i<combE.length; i++){ |
| 30 | + int percent = combE[i]; |
| 31 | + if(percent < uPercent) |
| 32 | + continue; |
| 33 | + uTotal += prices[i]; |
| 34 | + //System.out.println(uTotal); |
| 35 | + if(uTotal >= uPrice){ |
| 36 | + //System.out.println("넘음!"); |
| 37 | + candidates[0] += 1; |
| 38 | + continue outer; |
| 39 | + } |
| 40 | + } |
| 41 | + candidates[1] += uTotal; |
| 42 | + } |
| 43 | + //System.out.println(String.format("중간결과: %d %d", candidates[0], candidates[1])); |
| 44 | + boolean b1 = answer1 <= candidates[0]; |
| 45 | + boolean b2 = answer2 <= candidates[1]; |
| 46 | + if(answer1 == candidates[0]){ |
| 47 | + if(answer2 <= candidates[1]){ |
| 48 | + answer2 = candidates[1]; |
| 49 | + } |
| 50 | + }else if(answer1 < candidates[0]){ |
| 51 | + answer1 = candidates[0]; |
| 52 | + answer2 = candidates[1]; |
| 53 | + } |
| 54 | + |
| 55 | + //### |
| 56 | + } |
| 57 | + |
| 58 | + return new int[]{answer1, answer2}; |
| 59 | + } |
| 60 | + private void getComb(){ |
| 61 | + dfs(0); |
| 62 | + } |
| 63 | + private void dfs(int index){ |
| 64 | + if(index == NOfE){ |
| 65 | + combs.add(comb.clone()); |
| 66 | + return; |
| 67 | + } |
| 68 | + for(int coupon: coupons){ |
| 69 | + comb[index] = coupon; |
| 70 | + dfs(index+1); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
0 commit comments