dp 문제... 어려웠다
오랜만에 풀어서 그런지 대충 규칙은 찾았지만 점화식 도출하는 것이 어려웠다.
결국 다른분들 블로그를 찾아보고 풀었다.
동전시리즈 더 풀어봐야겠다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testCase = Integer.parseInt(br.readLine());
for(int t=0;t<testCase;t++){
int n = Integer.parseInt(br.readLine());
String[] arr = br.readLine().split(" ");
int[] coins = new int[arr.length];
for(int i=0;i<arr.length;i++){
coins[i] = Integer.parseInt(arr[i]);
}
int m = Integer.parseInt(br.readLine());
int[] dp = new int[m+1];
dp[0] = 1;
for(int i=0;i<coins.length;i++){
int coin = coins[i];
for(int j=coin;j<dp.length;j++){
dp[j] += dp[j-coin];
}
}
System.out.println(dp[m]);
}
}
}