Language: C++

//#include <bits/stdc++>
#include<iostream>
using namespace std;

int solve(int weights[], int values[], int n, int W, int index, int dp[][]){
    if(index==n-1){
        if(W>=weights[index]){
            return values[index];
        }else{
            return 0;
        }
    }
    if(index>=n){
        return 0;
    }
    if(W<=0){
        return 0;
    }
    if(dp[index][W]!=-1){
        return dp[index][W];
    }

    //without including this weight
    int ans1=solve(weights, values, n, W, index+1, dp);

    //including this weight
    int ans2=0;
    if(W-weights[index]>=0)
        ans2=values[index]+solve(weights, values, n, W-weights[index], index+1, dp);

    int res=max(ans1, ans2);
    dp[index][W]=res;
    return res;
}

int main(){
    int n;
    cin>>n;

    int W;
    cin>>W;

    int weights[n];
    int values[n];

    for(int i=0; i<n; i++){
        cin>>weights[i];
        cin>>values[i];
    }

    int dp[n+1][W+1];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=W; j++){
            dp[i][j]=-1;
        }
    }

    int maxprofit=solve(weights, values, n, W, 0, dp);
    cout<<maxprofit<<endl;


}

Compiler output:
a.cc:5:69: error: declaration of 'dp' as multidimensional array must have bounds for all dimensions except the first
    5 | int solve(int weights[], int values[], int n, int W, int index, int dp[][]){
      |                                                                     ^~
a.cc: In function 'int solve(...)':
a.cc:6:8: error: 'index' was not declared in this scope
    6 |     if(index==n-1){
      |        ^~~~~
a.cc:6:15: error: 'n' was not declared in this scope
    6 |     if(index==n-1){
      |               ^
a.cc:7:12: error: 'W' was not declared in this scope
    7 |         if(W>=weights[index]){
      |            ^
a.cc:7:15: error: 'weights' was not declared in this scope
    7 |         if(W>=weights[index]){
      |               ^~~~~~~
a.cc:8:20: error: 'values' was not declared in this scope
    8 |             return values[index];
      |                    ^~~~~~
a.cc:13:8: error: 'index' was not declared in this scope
   13 |     if(index>=n){
      |        ^~~~~
a.cc:13:15: error: 'n' was not declared in this scope
   13 |     if(index>=n){
      |               ^
a.cc:16:8: error: 'W' was not declared in this scope
   16 |     if(W<=0){
      |        ^
a.cc:19:8: error: 'dp' was not declared in this scope
   19 |     if(dp[index][W]!=-1){
      |        ^~
a.cc:19:11: error: 'index' was not declared in this scope
   19 |     if(dp[index][W]!=-1){
      |           ^~~~~
a.cc:19:18: error: 'W' was not declared in this scope
   19 |     if(dp[index][W]!=-1){
      |                  ^
a.cc:24:20: error: 'weights' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                    ^~~~~~~
a.cc:24:29: error: 'values' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                             ^~~~~~
a.cc:24:37: error: 'n' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                                     ^
a.cc:24:40: error: 'W' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                                        ^
a.cc:24:43: error: 'index' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                                           ^~~~~
a.cc:24:52: error: 'dp' was not declared in this scope
   24 |     int ans1=solve(weights, values, n, W, index+1, dp);
      |                                                    ^~