코끼리
[백준] 2293 동전 1 [DP]
NaZZU
2024. 9. 12. 13:25
이번 단계가 저번 단계의 결과값을 포함하고 있음을 이용한 문제이다
수업듣고 써야지
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
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Channels;
namespace real연습
{
internal class Program
{
static void Main(string[] args)
{
int[] arr = Array.ConvertAll(Console.ReadLine().Trim().Split(), int.Parse);
int[] dp = new int[arr[1] + 1];
dp[0] = 1;
for (int i = 0; i < arr[0]; i++)
{
int coin = int.Parse(Console.ReadLine());
for (int j = coin; j <= arr[1]; j++)
{
dp[j] += dp[j - coin];
}
}
Console.WriteLine(dp[arr[1]]);
}
}
}
|
cs |