Anonymous user
Knapsack problem/Unbounded: Difference between revisions
→{{header|C}}
m (→{{header|Visual Basic}}: Works with) |
|||
Line 183:
{{trans|Fortran}}
<c>#include <stdio.h>
double min(double a, double b) {
}
struct Bounty {
int value;
double weight;
double volume;
};
int n[3];▼
struct Bounty panacea = {3000, 0.3, 0.025},
ichor = {1800, 0.2, 0.015},
gold = {2500, 2.0, 0.002},
sack = { 0, 25.0, 0.25 },
current;
#define CALC(V) current.V = i * panacea.V + j * ichor.V + k * gold.V
int main()▼
int i, j, k;▼
▲int main() {
maxPanacea = MIN( sack.weight / panacea.weight, sack.volume / panacea.volume );▼
▲ int i, j, k;
maxIchor = MIN( sack.weight / ichor.weight, sack.volume / ichor.volume );▼
double total_weight, total_volume;
maxGold = MIN( sack.weight / gold.weight, sack.volume / gold.volume );▼
int max_panacea, max_ichor, max_gold, max_value = 0;
▲ int n[3];
{▼
{▼
for (i = 0; i <= max_panacea;
for (j = 0; j
for
if (current.weight > sack.weight || current.volume > sack.volume)
▲ {
if
n[1] = j;
n[2] = k;
}
}
printf("Maximum value achievable is %d\n"▼
"This is achieved by carrying (one solution) %d panacea, %d ichor and %d gold\n"
▲ printf("Maximum value achievable is %d\n"
"
max_value,
}</c>
|