다이나믹 프로그래밍 한접시
[백준] 1912번: 연속 합 [C#]
NaZZU
2024. 4. 27. 00:09
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
|
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());
//Test test = new Test();
//test.Age = 1;
//Console.WriteLine(test.Age);
_1912_boj boj = new _1912_boj();
boj.boj_1912();
}
}
internal class _1912_boj
{
public void boj_1912()
{
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 < dp.Length; i++)
{
dp[i] = Math.Max(arr[i], dp[i - 1] + arr[i]);
}
Console.WriteLine(dp.Max()) ;
}
}
}
|
cs |