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?
Sign in to answer questions and track your progress
Sign In