Language: C++

#include <iostream>
using namespace std;
#define MAX 100

int N,W;
int v[MAX],w[MAX];
int dp[MAX+1][200+1];

int func(int i,int j){
    int res;
    if(dp[i][j]>=0)return dp[i][j];
    if(i==N){
        res=0;
    }
    else if (j<w[i]){
        res=func(i+1,j);
    }
    else{
        res=max(func(i+1,j), func(i+1,j-w[i])+v[i]);
    }
    return dp[i][j]=res;
}

int main(){
    cin>>N>>W;
    for (int i=0; i<N; i++)cin>>v[i]>>w[i];
    for (int i=0; i<MAX+1; i++) {
        for (int j=0; j<MAX+1; j++) {
            dp[i][j]=-1;
        }
    }
    cout<<func(0,W)<<endl;;
    return 0;
}#include <iostream>
using namespace std;
#define MAX 100

int N,W;
int v[MAX],w[MAX];
int dp[MAX+1][200+1];

int func(int i,int j){
    int res;
    if(dp[i][j]>=0)return dp[i][j];
    if(i==N){
        res=0;
    }
    else if (j<w[i]){
        res=func(i+1,j);
    }
    else{
        res=max(func(i+1,j), func(i+1,j-w[i])+v[i]);
    }
    return dp[i][j]=res;
}

int main(){
    cin>>N>>W;
    for (int i=0; i<N; i++)cin>>v[i]>>w[i];
    for (int i=0; i<MAX+1; i++) {
        for (int j=0; j<MAX+1; j++) {
            dp[i][j]=-1;
        }
    }
    cout<<func(0,W)<<endl;;
    return 0;
}#include <iostream>
using namespace std;
#define MAX 100

int N,W;
int v[MAX],w[MAX];
int dp[MAX+1][200+1];

int func(int i,int j){
    int res;
    if(dp[i][j]>=0)return dp[i][j];
    if(i==N){
        res=0;
    }
    else if (j<w[i]){
        res=func(i+1,j);
    }
    else{
        res=max(func(i+1,j), func(i+1,j-w[i])+v[i]);
    }
    return dp[i][j]=res;
}

int main(){
    cin>>N>>W;
    for (int i=0; i<N; i++)cin>>v[i]>>w[i];
    for (int i=0; i<MAX+1; i++) {
        for (int j=0; j<MAX+1; j++) {
            dp[i][j]=-1;
        }
    }
    cout<<func(0,W)<<endl;;
    return 0;
}#include <iostream>
using namespace std;
#define MAX 100

int N,W;
int v[MAX],w[MAX];
int dp[MAX+1][200+1];

int func(int i,int j){
    int res;
    if(dp[i][j]>=0)return dp[i][j];
    if(i==N){
        res=0;
    }
    else if (j<w[i]){
        res=func(i+1,j);
    }
    else{
        res=max(func(i+1,j), func(i+1,j-w[i])+v[i]);
    }
    return dp[i][j]=res;
}

int main(){
    cin>>N>>W;
    for (int i=0; i<N; i++)cin>>v[i]>>w[i];
    for (int i=0; i<MAX+1; i++) {
        for (int j=0; j<MAX+1; j++) {
            dp[i][j]=-1;
        }
    }
    cout<<func(0,W)<<endl;;
    return 0;
}#include <iostream>
using namespace std;
#define MAX 100

int N,W;
int v[MAX],w[MAX];
int dp[MAX+1][200+1];

int func(int i,int j){
    int res;
    if(dp[i][j]>=0)return dp[i][j];
    if(i==N){
        res=0;
    }
    else if (j<w[i]){
        res=func(i+1,j);
    }
    else{
        res=max(func(i+1,j), func(i+1,j-w[i])+v[i]);
    }
    return dp[i][j]=res;
}

int main(){
    cin>>N>>W;
    for (int i=0; i<N; i++)cin>>v[i]>>w[i];
    for (int i=0; i<MAX+1; i++) {
        for (int j=0; j<MAX+1; j++) {
            dp[i][j]=-1;
        }
    }
    cout<<func(0,W)<<endl;;
    return 0;
}

Compiler output:
a.cc:34:2: error: stray '#' in program
   34 | }#include <iostream>
      |  ^
a.cc:67:2: error: stray '#' in program
   67 | }#include <iostream>
      |  ^
a.cc:100:2: error: stray '#' in program
  100 | }#include <iostream>
      |  ^
a.cc:133:2: error: stray '#' in program
  133 | }#include <iostream>
      |  ^
a.cc:34:3: error: 'include' does not name a type
   34 | }#include <iostream>
      |   ^~~~~~~
a.cc:38:5: error: redefinition of 'int N'
   38 | int N,W;
      |     ^
a.cc:5:5: note: 'int N' previously declared here
    5 | int N,W;
      |     ^
a.cc:38:7: error: redefinition of 'int W'
   38 | int N,W;
      |       ^
a.cc:5:7: note: 'int W' previously declared here
    5 | int N,W;
      |       ^
a.cc:39:5: error: redefinition of 'int v [100]'
   39 | int v[MAX],w[MAX];
      |     ^
a.cc:6:5: note: 'int v [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |     ^
a.cc:39:12: error: redefinition of 'int w [100]'
   39 | int v[MAX],w[MAX];
      |            ^
a.cc:6:12: note: 'int w [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |            ^
a.cc:40:5: error: redefinition of 'int dp [101][201]'
   40 | int dp[MAX+1][200+1];
      |     ^~
a.cc:7:5: note: 'int dp [101][201]' previously declared here
    7 | int dp[MAX+1][200+1];
      |     ^~
a.cc:42:5: error: redefinition of 'int func(int, int)'
   42 | int func(int i,int j){
      |     ^~~~
a.cc:9:5: note: 'int func(int, int)' previously defined here
    9 | int func(int i,int j){
      |     ^~~~
a.cc:57:5: error: redefinition of 'int main()'
   57 | int main(){
      |     ^~~~
a.cc:24:5: note: 'int main()' previously defined here
   24 | int main(){
      |     ^~~~
a.cc:67:3: error: 'include' does not name a type
   67 | }#include <iostream>
      |   ^~~~~~~
a.cc:71:5: error: redefinition of 'int N'
   71 | int N,W;
      |     ^
a.cc:5:5: note: 'int N' previously declared here
    5 | int N,W;
      |     ^
a.cc:71:7: error: redefinition of 'int W'
   71 | int N,W;
      |       ^
a.cc:5:7: note: 'int W' previously declared here
    5 | int N,W;
      |       ^
a.cc:72:5: error: redefinition of 'int v [100]'
   72 | int v[MAX],w[MAX];
      |     ^
a.cc:6:5: note: 'int v [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |     ^
a.cc:72:12: error: redefinition of 'int w [100]'
   72 | int v[MAX],w[MAX];
      |            ^
a.cc:6:12: note: 'int w [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |            ^
a.cc:73:5: error: redefinition of 'int dp [101][201]'
   73 | int dp[MAX+1][200+1];
      |     ^~
a.cc:7:5: note: 'int dp [101][201]' previously declared here
    7 | int dp[MAX+1][200+1];
      |     ^~
a.cc:75:5: error: redefinition of 'int func(int, int)'
   75 | int func(int i,int j){
      |     ^~~~
a.cc:9:5: note: 'int func(int, int)' previously defined here
    9 | int func(int i,int j){
      |     ^~~~
a.cc:90:5: error: redefinition of 'int main()'
   90 | int main(){
      |     ^~~~
a.cc:24:5: note: 'int main()' previously defined here
   24 | int main(){
      |     ^~~~
a.cc:100:3: error: 'include' does not name a type
  100 | }#include <iostream>
      |   ^~~~~~~
a.cc:104:5: error: redefinition of 'int N'
  104 | int N,W;
      |     ^
a.cc:5:5: note: 'int N' previously declared here
    5 | int N,W;
      |     ^
a.cc:104:7: error: redefinition of 'int W'
  104 | int N,W;
      |       ^
a.cc:5:7: note: 'int W' previously declared here
    5 | int N,W;
      |       ^
a.cc:105:5: error: redefinition of 'int v [100]'
  105 | int v[MAX],w[MAX];
      |     ^
a.cc:6:5: note: 'int v [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |     ^
a.cc:105:12: error: redefinition of 'int w [100]'
  105 | int v[MAX],w[MAX];
      |            ^
a.cc:6:12: note: 'int w [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |            ^
a.cc:106:5: error: redefinition of 'int dp [101][201]'
  106 | int dp[MAX+1][200+1];
      |     ^~
a.cc:7:5: note: 'int dp [101][201]' previously declared here
    7 | int dp[MAX+1][200+1];
      |     ^~
a.cc:108:5: error: redefinition of 'int func(int, int)'
  108 | int func(int i,int j){
      |     ^~~~
a.cc:9:5: note: 'int func(int, int)' previously defined here
    9 | int func(int i,int j){
      |     ^~~~
a.cc:123:5: error: redefinition of 'int main()'
  123 | int main(){
      |     ^~~~
a.cc:24:5: note: 'int main()' previously defined here
   24 | int main(){
      |     ^~~~
a.cc:133:3: error: 'include' does not name a type
  133 | }#include <iostream>
      |   ^~~~~~~
a.cc:137:5: error: redefinition of 'int N'
  137 | int N,W;
      |     ^
a.cc:5:5: note: 'int N' previously declared here
    5 | int N,W;
      |     ^
a.cc:137:7: error: redefinition of 'int W'
  137 | int N,W;
      |       ^
a.cc:5:7: note: 'int W' previously declared here
    5 | int N,W;
      |       ^
a.cc:138:5: error: redefinition of 'int v [100]'
  138 | int v[MAX],w[MAX];
      |     ^
a.cc:6:5: note: 'int v [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |     ^
a.cc:138:12: error: redefinition of 'int w [100]'
  138 | int v[MAX],w[MAX];
      |            ^
a.cc:6:12: note: 'int w [100]' previously declared here
    6 | int v[MAX],w[MAX];
      |            ^
a.cc:139:5: error: redefinition of 'int dp [101][201]'
  139 | int dp[MAX+1][200+1];
      |     ^~
a.cc:7:5: note: 'int dp [101][201]' previously declared here
    7 | int dp[MAX+1][200+1];
      |     ^~
a.cc:141:5: error: redefinition of 'int func(int, int)'
  141 | int func(int i,int j){
      |     ^~~~
a.cc:9:5: note: 'int func(int, int)' previously defined here
    9 | int func(int i,int j){
      |     ^~~~
a.cc:156:5: error: redefinition of 'int main()'
  156 | int main(){
      |     ^~~~
a.cc:24:5: note: 'int main()' previously defined here
   24 | int main(){
      |     ^~~~