We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- DP: Coin Change
- Discussions
DP: Coin Change
DP: Coin Change
Sort by
recency
|
96 Discussions
|
Please Login in order to post a comment
include
include
include
using namespace std;
vector coinChangeDP(const vector& coins, int amount) { vector dp(amount+1,numeric_limits::max()); dp[0]=0;
} int main() { vector coin = {1,5,10,25}; int amount = 47;
}
Simple Ruby DP solution:
Anyone know what change is needed to only return the number of odd solutions? Eg given the coins [1,2,5] and amount 5. The solutions are: [1,1,1,1,1] [2,111] [2,2,1] [5] There are four solutions, but only three odd solutions. I'm tearing my hair out trying to solve this.
def make_change(coins, n): lookup = [1] + [0] * n coins_used_list = [] coins_used_counter = 0 for coin in coins: for amount in range(n+1-coin): lookup[amount+coin] += lookup[amount] return lookup[n]
make_change(coins = [1,2,5], n = 5)
In c++ starter code, result is in int format and due to that I am getting WA in 3 test cases. Remember to change this if you are getting WA.