What would be the solution to this problem? I think it would be rather tricky because you would have to juggle three characteristics.
Here is my attempt: p-value, s-weight, k-amount, max-maximum weight,
m-number of items to take
static int solution(int[] s, int[] p, int[] k, int max) {
int[,] matrix = new int[s.Length + 1, max + 1];
for (int i = 1; i <= s.Length; i++)
{
for (int j = 0; j <= max; j++)
{
int m = 1;
for(int z = k[i - 1]; z > 0; z--)
{
if(z * s[i - 1] <= j)
{
m = z;
break;
}
}
if (s[i - 1] * m <= 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];
}