

최대 가치를 구하는게 아닌 모든 경우의 수를 구하는 문제이다.
백준 9084번과 동일한 문제다.
import java.util.Arrays;
import java.util.Scanner;
public class bj6109 {
static Scanner scanner = new Scanner(System.in);
static int[] cent;
public static void main(String[] args) {
int N, C;
N = scanner.nextInt();
C = scanner.nextInt();
inputCent(N, C);
System.out.println(findAnswer(N, C));
scanner.close();
}
public static void inputCent(int N, int C){
System.out.println("inputCent()");
int i;
cent = new int[C];
for(i = 0; i < C; i++){
cent[i] = scanner.nextInt();
}
}
public static int findAnswer(int N, int C){
System.out.println("findAnswer()");
int i, j;
int[] DP = new int[N+1];
DP[0] = 1;
for(i = 0; i < cent.length; i++){
for(j = 1; j <= N; j++){
if(j - cent[i] > 0){
DP[j] = DP[j] + DP[j - cent[i]];
}
else if(j - cent[i] == 0)
{
DP[j]++;
}
System.out.print(DP[j] + " ");
}
System.out.println();
}
return DP[N];
}
}