Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created June 19, 2017 13:34
Show Gist options
  • Select an option

  • Save developer-sdk/65e7f5491489a747040b1dd532cc7450 to your computer and use it in GitHub Desktop.

Select an option

Save developer-sdk/65e7f5491489a747040b1dd532cc7450 to your computer and use it in GitHub Desktop.
백준, 동전 1, 2293, 다이나믹 프로그래밍
package sdk.backjun.dp;
import java.util.Scanner;
/**
* 백준, 동전 1, 2293
*
* @author whitebeard-k
*
*/
public class Problem2293 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
int[] coins = new int[N+1];
for(int i = 1; i <= N; i++)
coins[i] = sc.nextInt();
sc.close();
int[] dp = new int[K+1];
dp[0] = 1;
for(int i = 1; i <= N; i++ ){
for(int j = 0; j <= K; j++ ){
if(j - coins[i] >= 0) {
dp[j] += dp[j-coins[i]];
}
}
System.out.printf("coin %d: ", coins[i]);
for(int n : dp)
System.out.printf("%d ", n);
System.out.println();
}
System.out.println(dp[K]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment