|
| 1 | +import java.io.*; |
| 2 | + |
| 3 | +public class YJ_9084 { |
| 4 | + public static void main(String[] args) throws IOException{ |
| 5 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 6 | + int T = Integer.parseInt(br.readLine()); |
| 7 | + for(int t=0; t<T; t++){ |
| 8 | + int N = Integer.parseInt(br.readLine()); |
| 9 | + int[] coins = new int[N]; |
| 10 | + String[] c = br.readLine().split("\\s"); |
| 11 | + for(int i=0; i<N; i++){ |
| 12 | + coins[i] = Integer.parseInt(c[i]); |
| 13 | + } |
| 14 | + int M = Integer.parseInt(br.readLine()); |
| 15 | + |
| 16 | + System.out.println(dp(coins,M)); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + static int dp(int[] coins, int M){ |
| 21 | + int[] dp = new int[M+1]; |
| 22 | + dp[0] = 1; |
| 23 | + |
| 24 | + for(int coin : coins){ |
| 25 | + for(int i=0; i<M+1; i++){ |
| 26 | + if(coin>i){ |
| 27 | + continue; |
| 28 | + } |
| 29 | + dp[i] += dp[i-coin]; |
| 30 | + } |
| 31 | + } |
| 32 | + return dp[M]; |
| 33 | + } |
| 34 | +} |
0 commit comments