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