-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path동전 1.java
More file actions
40 lines (34 loc) · 1.14 KB
/
동전 1.java
File metadata and controls
40 lines (34 loc) · 1.14 KB
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
import java.util.*;
import java.io.*;
public class Main {
static int n, k;
static int[] coins;
static int[][] dp;
static StringTokenizer st;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception{
pre_setting();
System.out.println(recur(0, 0));
}
static int recur(int now, int sum){
if(k == sum) return 1;
if(k < sum || n <= now) return 0;
if(dp[now][sum] != -1) return dp[now][sum];
int rot = 0;
for(int i = 0; sum + (i * coins[now]) <= k; i++){
rot += recur(now + 1, sum + coins[now] * i);
}
return dp[now][sum] = rot;
}
static void pre_setting() throws Exception{
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
k = Integer.parseInt(st.nextToken());
dp = new int[n][k + 1];
coins = new int[n];
for(int i = 0; i < n; i++) {
coins[i] = Integer.parseInt(br.readLine());
Arrays.fill(dp[i], -1);
}
}
}