-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_Knapsack.c
35 lines (29 loc) · 885 Bytes
/
my_Knapsack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "my_mat.h"
int main()
{
// Read the items and their values and weights
char items[ITEMSAMOUNT];
int values[ITEMSAMOUNT];
int weights[ITEMSAMOUNT];
int selected_bool[ITEMSAMOUNT];
for (size_t i = 0; i < ITEMSAMOUNT-1; i++)
{
scanf("%c", &items[i]);
scanf("%d", &values[i]);
scanf("%d ", &weights[i]);
}
scanf("%c", &items[ITEMSAMOUNT-1]);
scanf("%d", &values[ITEMSAMOUNT-1]);
scanf("%d", &weights[ITEMSAMOUNT-1]);
// Print the maximum profit and the selected items
printf("Maximum profit: %d\n", knapSack(weights, values, selected_bool));
printf("Selected items:");
for (size_t i = 0; i < ITEMSAMOUNT; i++)
if (selected_bool[i] == 1)
printf(" %c", items[i]);
return 0;
}