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

[ BOJ/C# ] 11726 2×n 타일링

by 왹져박사 2023. 9. 22.
728x90

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

 

11726번: 2×n 타일링

2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다.

www.acmicpc.net

이번에도 다이나믹 프로그래밍이다. DP유형의 문제들은 몇 번 풀어보니 비슷한 느낌이다. 

처음에는 메서드로 풀었는데, 시간초과가 났다. 

언제 C# 시간 줄이기를 정리해야겠다. 

using System;

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

            int n = int.Parse(sr.ReadLine());
            int[] ints = new int[1001];
            ints[1] = 1;
            ints[2] = 2;
            for (int i = 3; i <= n; i++)
                ints[i] = (ints[i - 1] + ints[i - 2]) % 10007;
            sw.Write(ints[n]);
            sr.Close();
            sw.Flush();
            sw.Close();
        }
    }
}

728x90

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

[ BOJ/C# ] 9461 파도반 수열  (0) 2023.09.24
[ BOJ/C# ] 11727 2×n 타일링 2  (0) 2023.09.23
[ BOJ/C# ] 1003 피보나치 함수  (0) 2023.09.21
[ BOJ/C# ] 9095 1, 2, 3 더하기  (0) 2023.09.19
[ BOJ/C# ] 1463 1로 만들기  (0) 2023.09.18