Language: C++

#include <iostream>
#include <unordered_map>
#include <climits>
using namespace std;
 
typedef long long int lli;
// create a map to store solutions of subproblems
//unordered_map<string, lli> lookup;
vector<lli> lookup(101,-1);
// Values (stored in array v)
// Weights (stored in array w)
// Number of distinct items (n)
// Knapsack capacity W
lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
{
    // base case: Negative capacity
     
    // base case: no items left or capacity becomes 0
    if (n < 0 || W == 0)
        return lookup[n];
 
    // construct an unique map key from dynamic elements of the input
   // string key = to_string(n) + "|" + to_string(W);
 
    // if sub-problem is seen for the first time, solve it and
    // store its result in a map
   // if (lookup.find(key) == lookup.end())
   // {
        // Case 1. include current item n in knapSack (v[n]) & recur for
        // remaining items (n - 1) with decreased capacity (W - w[n])
        lli include = v[n] + knapSack( w,v, n - 1, W - w[n]);
 
        // Case 2. exclude current item n from knapSack and recur for
        // remaining items (n - 1)
        lli exclude = knapSack(w,v, n - 1, W);
 
        // assign max value we get by including or excluding current item
        lookup[n] = max (include, exclude);
    //}
 
    // return solution to current sub-problem
    return lookup[n];
}
 
// 0-1 Knapsack problem
int main()
{
    int n, W;
	cin>>n >> W;
	vector <int> w(n+1), v(n+1);
	for (int i=1; i<=n; ++i){
		cin >>w[i] >>v[i];
	}
 
    cout << knapSack(w,v, n , W);
 
    return 0;
}

Compiler output:
a.cc:9:1: error: 'vector' does not name a type
    9 | vector<lli> lookup(101,-1);
      | ^~~~~~
a.cc:14:14: error: 'vector' was not declared in this scope
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |              ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <climits>
  +++ |+#include <vector>
    4 | using namespace std;
a.cc:14:21: error: expected primary-expression before 'int'
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                     ^~~
a.cc:14:30: error: 'vector' was not declared in this scope
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                              ^~~~~~
a.cc:14:30: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:14:37: error: expected primary-expression before 'int'
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                                     ^~~
a.cc:14:46: error: expected primary-expression before 'int'
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                                              ^~~
a.cc:14:53: error: expected primary-expression before 'int'
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                                                     ^~~
a.cc:14:58: error: expression list treated as compound expression in initializer [-fpermissive]
   14 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                                                          ^
a.cc: In function 'int main()':
a.cc:50:9: error: 'vector' was not declared in this scope
   50 |         vector <int> w(n+1), v(n+1);
      |         ^~~~~~
a.cc:50:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:50:17: error: expected primary-expression before 'int'
   50 |         vector <int> w(n+1), v(n+1);
      |                 ^~~
a.cc:52:23: error: 'w' was not declared in this scope
   52 |                 cin >>w[i] >>v[i];
      |                       ^
a.cc:52:30: error: 'v' was not declared in this scope
   52 |                 cin >>w[i] >>v[i];
      |                              ^
a.cc:55:22: error: 'w' was not declared in this scope
   55 |     cout << knapSack(w,v, n , W);
      |                      ^
a.cc:55:24: error: 'v' was not declared in this scope
   55 |     cout << knapSack(w,v, n , W);
      |                        ^
a.cc:55:21: error: 'knapSack' cannot be used as a function
   55 |     cout << knapSack(w,v, n , W);
      |             ~~~~~~~~^~~~~~~~~~~~