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