ปานกลาง 0 ข้อที่แก้แล้ว อัตราผ่าน 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.

เงื่อนไข

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.

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
coins = [1, 2]
amount = 4

ผลลัพธ์ที่คาดหวัง:
expected = 3
อินพุต:
std::vector<long long> coins = {1, 2};
long long amount = 4;

ผลลัพธ์ที่คาดหวัง:
long long expected = 3;
อินพุต:
long[] coins = new long[] {1, 2};
long amount = 4;

ผลลัพธ์ที่คาดหวัง:
long expected = 3;

คำอธิบาย

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

ตัวอย่างที่ 2
อินพุต:
coins = [2]
amount = 3

ผลลัพธ์ที่คาดหวัง:
expected = 0
อินพุต:
std::vector<long long> coins = {2};
long long amount = 3;

ผลลัพธ์ที่คาดหวัง:
long long expected = 0;
อินพุต:
long[] coins = new long[] {2};
long amount = 3;

ผลลัพธ์ที่คาดหวัง:
long expected = 0;

คำอธิบาย

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

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก