Код: Выделить всё
# include
void knapsack(int n, float weight[], float profit[], float capacity){
float x[20], tp=0;
int i, j, u;
u = capacity;
for (int i = 0; i < n; i++)
x[i] = 0.0;
for (int i = 0; i < n; i++)
{
if (weight[i]>u)
break;
else
{
x[i] = 1.0;
tp = tp + profit[i];
u = u-weight[i];
}
}
if (i
Подробнее здесь: [url]https://stackoverflow.com/questions/78496442/a-simple-knapsack-code-not-showing-the-correct-output[/url]