Language: C

const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???

// ??\???
int n, W;
int w[MAX_N], v[MAX_N];

// ?????¢??????????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
// -1????????????????±??????§???????????¨?????¨???
int dp[MAX_N + 1][MAX_W + 1];

// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec_dp(int i, int j) {
  if (dp[i][j] != -1) {
    // ?????§?????????????????¨??????????????????????????????????????¨
    return dp[i][j];
  }
  int res;
  if (i == n) {
    // ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
    res = 0;
  } else if (j < w[i]) {
    // ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
    res = rec_dp(i + 1, j);
  } else {
    // ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
    res = max(
        rec_dp(i + 1, j),
        rec_dp(i + 1, j - w[i]) + v[i]
    );
  }
  // ?????????????????????????¨???¶??????
  return dp[i][j] = res;
}

void solve_dp() {
  memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
//  for (int i = 0; i < MAX_N + 1; i++)
//    for (int j = 0; j < MAX_W + 1; j++)
//      dp[i][j] = -1;
  
  // 0????????\?????§??????W??\????????´?????????????????¨?????????
  cout << rec_dp(0, W) << endl;
}

Compiler output:
main.c:6:5: error: variably modified 'w' at file scope
    6 | int w[MAX_N], v[MAX_N];
      |     ^
main.c:6:15: error: variably modified 'v' at file scope
    6 | int w[MAX_N], v[MAX_N];
      |               ^
main.c:11:5: error: variably modified 'dp' at file scope
   11 | int dp[MAX_N + 1][MAX_W + 1];
      |     ^~
main.c:11:5: error: variably modified 'dp' at file scope
main.c: In function 'rec_dp':
main.c:29:11: error: implicit declaration of function 'max' [-Wimplicit-function-declaration]
   29 |     res = max(
      |           ^~~
main.c: In function 'solve_dp':
main.c:39:3: error: implicit declaration of function 'memset' [-Wimplicit-function-declaration]
   39 |   memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
      |   ^~~~~~
main.c:1:1: note: include '<string.h>' or provide a declaration of 'memset'
  +++ |+#include <string.h>
    1 | const int MAX_N = 1000; // n????????§???
main.c:39:3: warning: incompatible implicit declaration of built-in function 'memset' [-Wbuiltin-declaration-mismatch]
   39 |   memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
      |   ^~~~~~
main.c:39:3: note: include '<string.h>' or provide a declaration of 'memset'
main.c:45:3: error: 'cout' undeclared (first use in this function)
   45 |   cout << rec_dp(0, W) << endl;
      |   ^~~~
main.c:45:3: note: each undeclared identifier is reported only once for each function it appears in
main.c:45:27: error: 'endl' undeclared (first use in this function)
   45 |   cout << rec_dp(0, W) << endl;
      |                           ^~~~