2024-04-29 23:18:10

예제가 많아서 좋은 예제 하나만 들고왔습니다.

 

 

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
49
50
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());
 
            _15486_boj boj = new _15486_boj();
 
            boj.boj_15486();
 
        }
    }
    internal class _15486_boj
    {
        public void boj_15486()
        {
            int count = int.Parse(Console.ReadLine());
 
            int[] day = new int[count];
            int[] profit = new int[count];
            int[] dp = new int[count + 1];
     
            for (int i = 0; i < count; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                day[i] = input[0];
                profit[i] = input[1];
            }
            for (int i = 0; i < count; i++)
            {
                if (i > 1)
                    dp[i] = Math.Max(dp[i - 1], dp[i]);
                if (i + day[i] <= count)
                    dp[i + day[i]] = Math.Max(dp[i + day[i]], dp[i] + profit[i]);
            }
            Console.WriteLine(dp.Max());
        }
    }
}
 
cs

 

개념 자체는 몹시 쉽지만 오늘따라 집중이 안되서 푸는데 너무 오래 걸렸다.