Recurrence equation calculation
Here is pseudocode for computing your function:


  Parameters:
  
  
  Integer $n$
  Arrays $W,V,S$ of length $n$
  
  
  function G(w):
  
  
  If $w = 0$, return $0$
  Let $\mathrm{max} \gets -\infty$
  For $i$ from $1$ to $n$:
  
  If $W[i] \leq w$:
  
  
  
  Let $x \gets G(w-S[i])+V[i]$
  
  
  
  
  If $x &gt; \mathrm{max}$, let $\mathrm{max} \gets x$
  
  
  Return $\mathrm{max}$
  


I used the notation $W[i],V[i],S[i]$ rather than $w_i,v_i,s_i$.