https://www.acmicpc.net/problem/11727
11727번: 2×n 타일링 2
2×n 직사각형을 1×2, 2×1과 2×2 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×17 직사각형을 채운 한가지 예이다.
www.acmicpc.net
2×n 타일링 문제와 거의 비슷하다.
n==1이면 1개,
n==2는 3,
n==3는 5,
n==4는 11,
n==5는 21
...로 진행된다. 이를 보면 n의 방법의 수는 (n-1)+2*(n-2)라는 것을 알 수 있다.
using System;
namespace B11727
{
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] = 3;
if (n > 2)
{
for (int i = 3; i <= n; i++)
ints[i] = (ints[i - 1] + 2 * ints[i - 2]) % 10007;
}
sw.Write(ints[n]);
sr.Close();
sw.Flush();
sw.Close();
}
}
}
'알고리즘 > 백준 BOJ' 카테고리의 다른 글
[ BOJ/C# ] 2606 바이러스 (1) | 2023.09.24 |
---|---|
[ BOJ/C# ] 9461 파도반 수열 (0) | 2023.09.24 |
[ BOJ/C# ] 11726 2×n 타일링 (0) | 2023.09.22 |
[ BOJ/C# ] 1003 피보나치 함수 (0) | 2023.09.21 |
[ BOJ/C# ] 9095 1, 2, 3 더하기 (0) | 2023.09.19 |