Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>

using namespace std;

struct Treasure
{

  int value;
  int weight;

  Treasure()
  {
    value = 0;
    weight = 0;
  }

  void operator()( Treasure t)
  {

    cout << t.value << "," << t.weight << endl;

  }

  Treasure& operator+=(const Treasure& t )
  {

    this->value += t.value;
    this->weight += t.weight;
    return *this;

  }

  Treasure operator+(const Treasure& t)
  {
    Treasure tmp;
    tmp.value = this->value + t.value;
    tmp.weight = this->weight + t.weight;
    return tmp;
  }

  Treasure operator-(const Treasure& t)
  {
    Treasure tmp;
    tmp.value = this->value - t.value;
    tmp.weight = this->weight - t.weight;
    return tmp;
  }

};

Treasure& max(Treasure& t1,Treasure& t2)
{

  if(t1.value == t2.value)
    {
      return (t1.weight < t2.weight) ? t1 : t2;
    }
  else
    {
      return (t1.value > t2.value) ? t1 : t2;
    }

}

int N,W;

Treasure memo[1000][1000];

Treasure tmp;

vector<Treasure> treasure(1000);

Treasure& Knapsack(int& currentWeight,int& currentCount)
{

  Treasure t1,t2,f;

  if(memo[currentWeight][currentCount].weight)
    {
      return memo[currentWeight][currentCount];
    }
  else if(N == currentCount)
    {
      return tmp;
    }
  else{

    t1 = Knapsack(currentWeight,currentCount + 1);

    if( W >= currentWeight + treasure[currentCount].weight)
      {
        t2 = Knapsack(currentWeight + treasure[currentCount].weight,currentCount + 1) + treasure[currentCount];
      }
    else
      {
        t2 = Knapsack(currentWeight,currentCount + 1);
      }

    memo[currentWeight][currentCount] = max(t1,t2);

    return max(t1,t2);

  }

}

int main()
{

  int caseNumber = 0;

 while(cin >> W && W != 0)
   {

     cin >> N;

     for(int i = 0; i < N; ++i)
       { scanf("%d,%d",&treasure[i].value,&treasure[i].weight); }

     Treasure result = Knapsack(0,0);

     memset(memo,0,sizeof(memo));

     treasure.erase(treasure.begin(),treasure.end());

     cout << "Case " << ++caseNumber << ":" << endl;

     cout << result.value << endl << result.weight << endl;

   }

 return 0;

}

Compiler output:
a.cc: In function 'Treasure& Knapsack(int&, int&)':
a.cc:93:46: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   93 |     t1 = Knapsack(currentWeight,currentCount + 1);
      |                                 ~~~~~~~~~~~~~^~~
a.cc:78:44: note:   initializing argument 2 of 'Treasure& Knapsack(int&, int&)'
   78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
      |                                       ~~~~~^~~~~~~~~~~~
a.cc:97:37: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   97 |         t2 = Knapsack(currentWeight + treasure[currentCount].weight,currentCount + 1) + treasure[currentCount];
      |                       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:78:25: note:   initializing argument 1 of 'Treasure& Knapsack(int&, int&)'
   78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
      |                    ~~~~~^~~~~~~~~~~~~
a.cc:101:50: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  101 |         t2 = Knapsack(currentWeight,currentCount + 1);
      |                                     ~~~~~~~~~~~~~^~~
a.cc:78:44: note:   initializing argument 2 of 'Treasure& Knapsack(int&, int&)'
   78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
      |                                       ~~~~~^~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:125:33: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  125 |      Treasure result = Knapsack(0,0);
      |                                 ^
a.cc:78:25: note:   initializing argument 1 of 'Treasure& Knapsack(int&, int&)'
   78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
      |                    ~~~~~^~~~~~~~~~~~~