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
|
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());
_11055_boj boj = new _11055_boj();
boj.boj_11055();
}
}
internal class _11055_boj
{
public void boj_11055()
{
int n = int.Parse(Console.ReadLine());
int[] arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] dp = new int[n];
dp[0] = arr[0];
for (int i = 1; i < n; i++)
{
int max = 0;
for (int j = i - 1; j >= 0; j--)
if (arr[j] < arr[i] && max < dp[j])
max = dp[j];
dp[i] = arr[i] + max;
}
Console.WriteLine(dp.Max());
}
}
}
|
cs |
가장 큰 수열의 합을 구하는 것이기 때문에 이전의 값들 중 max의 값을 가져와야 했지만, 그런 과정 없이 가장 가까운 값을 가져와서 합을 해줘서 틀렸었다.
'다이나믹 프로그래밍 한접시' 카테고리의 다른 글
[백준] 15486번: 퇴사 2 [C#] (0) | 2024.04.29 |
---|---|
[백준] 11053번: 가장 긴 증가하는 부분 수열 [C#] (0) | 2024.04.29 |
[백준] 1로 만들기 2 [Python] (0) | 2024.04.29 |
[백준] 2193번: 이찬수 [C#] (0) | 2024.04.28 |
[백준] 11727번: 2*n 타일링 2 [C#] (0) | 2024.04.28 |