Language: C++

/////////////////////////////////////////////////////////////////////////////////
//// SRM 151 DIV 2 500 pt
/////////////////////////////////////////////////////////////////////////////////
#include <string>
#include <stdio.h>
#include <math.h>
#include <sstream>
#include <iostream>     // std::cout
#include <algorithm>    // std::copy
#include <vector>       // std::vector
#include <set>
#include <iomanip>

#define REP(i,n) for(int i=0; i<(int)n; i++)
#define INF 1e9

using namespace std;

template <class T> string tos(T x) {stringstream s; s << x; return s.str();}
template <class T> string tos2(T x, unsigned int digit, const char fillBy) {stringstream s; s << setw(digit) << setfill(fillBy) << x; return s.str();}

class CollectingTokens {
    string tmp;
    vector <vector <int>> path[100];
    //    vector <int> T_A;
    //    vector <int> T_B;
    //    int T_tokens[105];
    //    int done[105];
    //    int memo[105];
    //    int max_value;
    int dp[100][100];
    int N, L;
public:
    
    int dfs(int cur, int flg) {
        //        cout << cur << endl;
        if (dp[cur][flg] >= 0)
            return dp[cur][flg];
        if ((flg == ((0x01 << N) - 1)) && (cur == 0))
            return 0;
        int ret = INF;
        for (int i = 0; i < path[cur].size(); i++) {
            int next = path[cur][i][0];
            if ((flg & (0x01 << next)) > 0) continue;
            int cost = path[cur][i][1];
            ret = min(ret, dfs(next, flg | (0x01 << next))+cost);
        }
        //        cout << cur << " ret: " << ret << endl;
        dp[cur][flg] = ret;
        return ret;
    }
    
    int maxTokens(int node_num, int line_num, vector <int> A, vector <int> B, vector <int> tokens) {
        //        for (int i = 0; i < 100; i++) {
        //            for (int j = 0; j < 100; j++) {
        //                dp[i][j] = -1;
        //            }
        //        }
        memset(dp, -1, sizeof(dp));
        N = node_num;
        L = line_num;
        for (int i = 0; i < A.size(); i++) {
            path[A[i]].push_back({B[i], tokens[i]});
        }
        //        for (int i = 0; i < tokens.size(); i++) {
        //            T_tokens[i+1] = tokens[i];
        //        }
        
        return dfs(0, 0x00);
    }
};

///////////////////////////////////////////////////////////////////////////////////

int N, M;
int coin[20];
int dp[50000];
int rec(int n) {
    
    if (dp[n] > 0) return dp[n];
    
    if (n < 0) {
        return 10000;
    }
    else if (n == 0) {
        return 0;
    }
    
    int ret = INF;
    REP(i, M) {
        ret = min(ret, rec(n - coin[i])+1);
    }
    return dp[n] = ret;
}

int main(int argc, const char * argv[]) {
//    std::vector<int> a{0,0,1,2,2,3,4,4};
//    std::vector<int> b{1,3,2,0,3,4,0,1};
//    std::vector<int> c{3,4,5,4,5,3,7,6};
//    CollectingTokens z;
//    cout << z.maxTokens(5, 8, a, b, c);
    //    vector <int> ret = c.digits(3);
    //    for (int i = 0; i < ret.size(); i++) cout << ret[i] << endl;
    
    memset(dp, -1, sizeof(dp));
    cin >> N >> M;
    REP(i, M) cin >> coin[i];
    cout << rec(N) << endl;
    
    return 0;
}

Compiler output:
a.cc: In member function 'int CollectingTokens::maxTokens(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
a.cc:59:9: error: 'memset' was not declared in this scope
   59 |         memset(dp, -1, sizeof(dp));
      |         ^~~~~~
a.cc:13:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   12 | #include <iomanip>
  +++ |+#include <cstring>
   13 | 
a.cc: In function 'int main(int, const char**)':
a.cc:105:5: error: 'memset' was not declared in this scope
  105 |     memset(dp, -1, sizeof(dp));
      |     ^~~~~~
a.cc:105:5: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'