Six Ways Or Three

vector<int> coins = {1, 3, 4};
vector<long long> count(6, 0);
count[0] = 1;

for (int x = 1; x <= 5; x++)
    for (int c : coins)
        if (x - c >= 0) count[x] += count[x - c];

cout << count[5];

You wanted the number of distinct multisets of coins summing to 5. What does this print, and what did you want?

A

It prints 5. The base case count[0] = 1 should be 0.

B

It prints 6; you wanted 3. Putting coins in the outer loop and x in the inner loop counts each multiset once.

C

It prints 3, which is already the multiset count.

D

It prints 6, and 6 is right: 1+1+3 and 1+3+1 spend different coins.