Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int grid[510][5100];
- int solve(int idx,int amount,vector<int> & coins){
- if(idx == (int) coins.size() or amount == 0){
- return amount == 0;
- }
- if(grid[idx][amount] != -1){
- return grid[idx][amount];
- }
- int res = 0;
- for(int i = 0; i <= amount / coins[idx]; i++){
- res += solve(idx + 1,amount - (coins[idx] * i),coins);
- }
- return grid[idx][amount] = res;
- }
- int change(int amount, vector<int>& coins) {
- memset(grid,-1,sizeof(grid));
- return solve(0,amount,coins);
- }
- };
Add Comment
Please, Sign In to add comment