• + 0 comments

    short c++ solution using interative dynamic programming

    long getWays(int n, vector<long> c) {
        vector<long> dp(n+1,0);
        dp[0]=1;
        int cs = c.size();
        
         for (int i = 0; i < cs; i++) {
             int coin = c[i];
             for (int j = coin; j <= n; j++) {
                 dp[j] += dp[j-coin];
             }
         }
         
        return dp[n];
    }