Algorithm/BOJ

C#) [BOJ] 9375 패션왕 신해빈 ★

HSH12345 2023. 1. 24. 23:38

9375번: 패션왕 신해빈 (acmicpc.net)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace _230124_1
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            List<int> resultList = new List<int>();
            

            int a = int.Parse(sr.ReadLine());
            for(int i = 0; i < a; i++)
            {
                int N = int.Parse(sr.ReadLine());
                Dictionary<string, int> dicCloth = new Dictionary<string, int>();

                for (int j = 0; j < N; j++)
                {
                    string[] arr = sr.ReadLine().ToString().Split(' ');
                    if (dicCloth.ContainsKey(arr[1]))
                    {
                        dicCloth[arr[1]]++;
                    }
                    else
                    {
                        dicCloth.Add(arr[1], 1);
                    }
                }

                int result = 1;
                foreach (var cloth in dicCloth.Values)
                {
                    result *= (cloth + 1);    //안 입는 경우를 고려하여 각 종류별 옷의 개수에 +1 해준 값을 곱함
                }

                resultList.Add(result - 1); // 알몸인 상태를 제외 
            }

            foreach(int result in resultList)
            {
                sw.WriteLine(result);
            }            

            sr.Close();
            sw.Close();
        }
    }
}

순열을 이해해도 조합공식이 이해가 안되는 문제...