File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ ```java
2+ import java.io.IOException;
3+ import java.io.*;
4+ import java.util.*;
5+
6+
7+ public class Main {
8+ static int[] dp,coins;
9+ static int coinCnt, goal;
10+
11+ public static void main(String[] args) throws IOException {
12+ init();
13+ process();
14+ print();
15+ }
16+
17+ public static void init() throws IOException {
18+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+ StringTokenizer st = new StringTokenizer(br.readLine());
20+ coinCnt = Integer.parseInt(st.nextToken());
21+ goal = Integer.parseInt(st.nextToken());
22+
23+ coins = new int[coinCnt];
24+ dp = new int[goal+1];
25+ dp[0] = 1;
26+
27+ for (int i = 0; i < coinCnt; i++) {
28+ coins[i] = Integer.parseInt(br.readLine());
29+ }
30+
31+
32+ }
33+
34+ public static void process() throws IOException {
35+
36+ for (int i = 0; i < coinCnt; i++) {
37+ int cost = coins[i];
38+
39+ for (int j = cost; j <= goal; j++) {
40+ dp[j] += dp[j-cost];
41+ }
42+ }
43+
44+ }
45+
46+
47+
48+
49+
50+
51+
52+ public static void print() {
53+ System.out.println(dp[goal]);
54+ }
55+ }
56+
57+ ```
You can’t perform that action at this time.
0 commit comments