st0le
11/8/2013 - 7:51 PM

Coin Change

Coin Change


    public static void main(String[] args) {

        int K = 4;

        int[] coins = new int[]{1,2,3};

        int[] ways = new int[K + 1];

        ways[0] = 1;

        for (int coin : coins)

            for (int i = coin; i <= K; i++)

                    ways[i] += ways[i - coin];

        System.out.println(Arrays.toString(ways));

        System.out.println(ways[K]);

    }