본문 바로가기
알고리즘/백준 BOJ

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

by 왹져박사 2023. 10. 5.
728x90

https://www.acmicpc.net/problem/9375

 

9375번: 패션왕 신해빈

첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로   (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.

www.acmicpc.net

입력에 따른 경우의 수를 구하는 문제이다. 

각 의상 종류의 개수+1 (해당 종류를 입지 않는 경우+1) 을 곱하면 모든 조합의 경우의 수가 나온다. 

모든 수에서 -1 (모든 종류를 입지 않는 경우..알몸)을 제외하면 문제에서 의도하는 경우의 수가 나온다. 

using System;
using System.IO;
using System.Text;

namespace B9375
{
    class Program
    {
        static void Main()
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb = new StringBuilder();

            int t = int.Parse(sr.ReadLine());
            for(int i = 0; i < t; i++)
            {
                Dictionary<string, int> dic = new Dictionary<string, int>();
                int result = 1;
                int n = int.Parse(sr.ReadLine());
                for(int j = 0; j < n; j++)
                {
                    string[] strs = sr.ReadLine().Split(' ');
                    if (dic.ContainsKey(strs[1])) dic[strs[1]]++;
                    else dic.Add(strs[1], 1);
                }
                foreach (var val in dic.Values) result *= (val + 1);
                sb.Append(result - 1 + "\n");  //아무것도 안 입는 경우의 수 제거
            }
            sw.Write(sb);
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

'알고리즘 > 백준 BOJ' 카테고리의 다른 글

[ BOJ/C# ] 2805 나무 자르기  (0) 2023.10.07
[ BOJ/C# ] 2579 계단 오르기  (0) 2023.10.07
[ BOJ/C# ] 11659 구간 합 구하기 4  (0) 2023.10.04
[ BOJ/C# ] 11651 좌표 정렬하기 2  (0) 2023.10.04
[ BOJ/C# ] 17626 Four Squares  (0) 2023.10.03