Tất cả thử thách
Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Count Coin Combinations

Count ways to make an amount with unlimited coins of specified denominations.

Use any number of each supplied denomination to make amount exactly. Count combinations, not orderings: two arrangements using the same counts of each coin are the same way. Denominations are distinct and positive.

Implement coin_sums(amount, coins).

Input

amount: The total amount to make.

coins: The available distinct denominations.

Output

Return the number of unordered combinations.

Ràng buộc

0 ≤ amount ≤ 200. There are 0 through 10 distinct denominations, each from 1 through 200. All counts fit signed 64-bit. Amount 0 has one way: choose no coins.

Ví dụ

Ví dụ 1
Đầu vào:
coins = [1, 2]
amount = 4

Kết quả mong đợi:
expected = 3
Đầu vào:
std::vector<long long> coins = {1, 2};
long long amount = 4;

Kết quả mong đợi:
long long expected = 3;
Đầu vào:
long[] coins = new long[] {1, 2};
long amount = 4;

Kết quả mong đợi:
long expected = 3;

Giải thích

The combinations are four 1s, two 1s with one 2, and two 2s.

Ví dụ 2
Đầu vào:
coins = [2]
amount = 3

Kết quả mong đợi:
expected = 0
Đầu vào:
std::vector<long long> coins = {2};
long long amount = 3;

Kết quả mong đợi:
long long expected = 0;
Đầu vào:
long[] coins = new long[] {2};
long amount = 3;

Kết quả mong đợi:
long expected = 0;

Giải thích

Any sum of 2-valued coins is even, so 3 is impossible.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.