title: Knapsack problem where there are three arrays: weight of an item array, value of an item array and amount of an item array
body: <p>What would be the solution to this problem? I think it would be rather tricky because you would have to juggle three characteristics. </p>
  
  <p>Here is my attempt:
  p-value, s-weight, k-amount, max-maximum weight, </p>
  
  <p>m-number of items to take</p>
  
  <p>static int solution(int[] s, int[] p, int[] k, int max)
          {</p>
  
  <pre><code>        int[,] matrix = new int[s.Length + 1, max + 1];
  
          for (int i = 1; i &lt;= s.Length; i++)
          {
  
              for (int j = 0; j &lt;= max; j++)
              {                    
  
                  int m = 1;
                  for(int z = k[i - 1]; z &gt; 0; z--)
                  {
                      if(z * s[i - 1] &lt;= j)
                      {                            
                          m = z;
                          break;
  
                      }
                  }                    
  
                  if (s[i - 1] * m &lt;= j)
                  {
                      matrix[i, j] =
                          Math.Max((p[i - 1] * m) + matrix[i - 1, j - s[i - 1] * m],
                      matrix[i - 1, j]);
                  }
                  else
                  {
                      matrix[i, j] = matrix[i - 1, j];
                  }
  
              }
          }
  
          return matrix[s.Length, max];
      }
  </code></pre>