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
39
40
41
42
43
44
45
46
47
48
|
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
namespace 연습장
{
internal class Program
{
static StringBuilder sb = new StringBuilder();
static void Main(string[] args)
{
using var reader = new StreamReader(Console.OpenStandardInput());
using var print = new StreamWriter(Console.OpenStandardOutput());
_2747_boj boj = new _2747_boj();
boj.boj_2747();
}
}
internal class _2747_boj
{
public void boj_2747()
{
int n = int.Parse(Console.ReadLine());
long[] dp = new long[n + 1];
dp[0] = 0;
if (n >= 1)
dp[1] = 1;
if (n >= 2)
dp[2] = 1;
if (n <= 2){
Console.WriteLine(dp[n]);
return;
}
for (int i = 3; i <= n; i++)
{
dp[i] = dp[i - 2] + dp[i - 1];
}
Console.WriteLine(dp[n]);
}
}
}
|
cs |
'다이나믹 프로그래밍 한접시' 카테고리의 다른 글
[백준] 11047번: 동전 0 [C#] (0) | 2024.05.10 |
---|---|
[백준] 15988번: 1, 2, 3 더하기 3 [C#] (0) | 2024.05.03 |
[백준] 9084번: 동전 [C#] (0) | 2024.05.02 |
[백준] 2156번: 포도주 시식 [C#] (1) | 2024.05.01 |
[백준] 가장 긴 증가하는 부분 수열 4 [C#] (0) | 2024.04.30 |