728x90
SMALL

C#

 

 

 

using System;

public class Solution {
          int sign = 0;
        int earn = 0;
        public int[] solution(int[,] users, int[] emoticons)
        {
            int[] answer = new int[2] { 0, 0 };
            int[] array = new int[emoticons.Length];

            ExhaustiveSearch(array, 0, users, emoticons);

            answer[0] = sign;
            answer[1] = earn;

            return answer;
        }

        public void ExhaustiveSearch(int[] arr, int start, int[,] users, int[] emoticons)
        {
            if (start == arr.Length)
            {
                calculoate(arr, users, emoticons);
                return;
            }

            for (int iPos = 10; iPos <= 40; iPos += 10)
            {
                arr[start] = iPos;
                ExhaustiveSearch(arr, start + 1, users, emoticons);
            }
        }

        public void calculoate(int[] arr, int[,] users, int[] emoticons)
        {
            int count = 0;
            int earn_t = 0;

            for (int iPos = 0; iPos < users.GetLength(0); iPos++)
            {
                int discount = users[iPos, 0];
                int price = users[iPos, 1];
                int sum = 0;

                for (int jPos = 0; jPos < arr.Length; jPos++)
                {
                    if (arr[jPos] >= discount)
                        sum += (emoticons[jPos] / 100) * (100 - arr[jPos]);
                }

                if (sum >= price)
                    count++;
                else
                    earn_t += sum;
            }

            if (count > sign)
            {
                sign = count;
                earn = earn_t;
                return;
            }
            else if (count == sign)
            {
                if (earn < earn_t)
                {
                    earn = earn_t;
                }
            }
        }
}

 

 

 

////////////////////

 

 

 

using System;
using System.Collections.Generic;
public class Solution {
    public int[] solution(int[,] users, int[] emoticons) {
        int[] answer = new int[] {0,0};

            Stack<int[]> stack = new Stack<int[]>();
            List<int[]> combination = new List<int[]>();

            int cnt = 0;
            int total = 0;
            int[] temp = new int[emoticons.Length];

            for (int j = 1; j < 5; j++) 
            {
                temp[0] = j * 10;
                tempA(temp, 0, combination);
            }

            int price = 0;
            
            foreach (var c in combination)
            {
                total = 0;
                cnt = 0;

                for (int u =0; u < users.GetLength(0); u++)
                {
                    price = 0;

                    for (int e = 0;e<emoticons.Length;e++)
                    {
                        if(users[u,0] <= c[e])
                        {
                            price += emoticons[e] * (100 - c[e]) / 100;
                        }
                    }

                    if(price >= users[u, 1])
                    {
                        cnt += 1;
                    }
                    else
                    {
                        total += price;
                    }

                }

               if (cnt > answer[0] ||
                    (cnt == answer[0] && total > answer[1]))
                {
                    answer[0] = cnt;
                    answer[1] = total;
                }


            }

            return answer;
    }

     public static void tempA(int[] temp, int now, List<int[]> combi)
        {
            if (now+1 == temp.Length) 
            {
                combi.Add(temp.Clone() as int[]);
                return;
            }

            now = now + 1;
            for (int j = 1; j < 5; j++) 
            {
                temp[now] = j*10;
                tempA(temp, now, combi);
            }
        }
}
728x90

설정

트랙백

댓글