다이나믹 프로그래밍 한접시
[백준] 2133번: 타일 채우기 [C#]
NaZZU
2024. 4. 13. 22:19
점화식: dp[N] = dp[N-2] * 3 + ∑(dp[i] * 2) (i 는 0이 될때까지 2씩 감소)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 연습장
{
internal class _2133_boj
{
public void boj_2133()
{
int N = int.Parse(Console.ReadLine());
int[] dp = Enumerable.Repeat(0, 31).ToArray();
dp[0] = 1;
dp[2] = 3;
for (int a = 4; a <= N; a += 2)
{
dp[a] = dp[a - 2] * 3;
for (int i = a - 2; i >= 2; i -= 2)
{
dp[a] += dp[i - 2] * 2;
}
}
Console.WriteLine(dp[N]);
}
}
}
|
cs |
나는 이에 대한 실로 놀라운 증명법을 발견했다. (하지만) 시간이 부족하여 이를 적지 않겠다.