2024-05-10 23:40:43

 

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());
 
            _11047_boj boj = new _11047_boj();
 
            boj.boj_11047();
 
        }
    }
        internal class _11047_boj
    {
        public void boj_11047()
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
 
            int[] arr = new int[input[0]];
 
            for (int i = 0; i < input[0]; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
 
            int[] dp = new int[input[1+ 1];
            dp[0= 0;
 
            for (int i = 0; i < input[0]; i++)
            {
                for (int j = arr[i]; j <= input[1]; j++)
                {
                    dp[j] = 1 + dp[j - arr[i]];
                }
            }
            Console.WriteLine(dp[input[1]]);
        }
    }
}
 
cs

 

그리디는 안 읶뜎하니깐 다이나믹 프로그래밍으로 풀었다