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

[BOJ C#] 2775 부녀회장이 될테야

by 왹져박사 2023. 1. 25.
728x90

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

namespace _2775
{
    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++)
            {
                int k = int.Parse(sr.ReadLine());
                int n = int.Parse(sr.ReadLine());

                int[,] apt = new int[k+1, n];
                for(int j = 0; j <= k; j++)
                {
                    apt[j, 0] = 1;
                }
                for(int j = 1; j < n; j++)
                {
                    apt[0, j] = j+1;
                }
                for(int kIndex=1; kIndex<=k; kIndex++)
                {
                    for(int nIndex=1; nIndex<n; nIndex++)
                    {
                        apt[kIndex, nIndex] = apt[kIndex-1, nIndex] + apt[kIndex, nIndex - 1];
                    }

                }
                sb.Append(apt[k, n-1]);
                sb.Append("\n");
            }
            sw.WriteLine(sb);

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

728x90

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

[BOJ C#] 10250 ACM 호텔  (0) 2023.01.25
[BOJ C#] 2798 블랙잭  (0) 2023.01.25
[BOJ C#]11659 구간 합 구하기 4  (0) 2023.01.16
[BOJ C#] 11720 숫자의 합  (0) 2023.01.15
[BOJ C#] 10988 팰린드롬  (0) 2023.01.15