coins lists coin values, and you have as many coins of each value as you like. Return the number of different ways to pay exactly amount.
Two ways are the same when they use the same number of coins of each value, whatever order the coins are counted in: 2 + 1 + 1 and 1 + 2 + 1 are one way, not two. If amount can't be paid at all, return 0.
The six ways are 4 + 2, 4 + 1 + 1, 2 + 2 + 2, 2 + 2 + 1 + 1, 2 + 1 + 1 + 1 + 1 and six 1s.
Every sum of 2s and 4s is even, so 7 can't be paid.
Paying nothing takes no coins, and that counts as exactly one way.
Constraints
1 <= coins.length <= 3001 <= coins[i] <= 5000coins are all different.0 <= amount <= 5000t from 1 to amount, the number of ways to pay t with these coins is at most 2³¹ - 1. So the answer, and every count along the way, fits in a 32-bit signed integer.To count each way once, build every way in one fixed order: first decide how many of the first coin to use, then how many of the second, and so on. Then 2 + 1 and 1 + 2 are the same set of choices.
6