Program to implement knapsack problem using greedy method
//Program to implement knapsack problem using greedy method
What actually Problem Says ?
- Given a set of items, each with a weight and a value.
- Determine the number of each item to include in a collection so that the total weight is less than a given limit and the total value is as large as possible.
- It derives its name from the problem faced by someone who is constrained by afixed-size knapsack and must fill it with the most useful items.
Program :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
Enter the no. of objects:- 7
Enter the wts and profits of each object:-
2 10
3 5
5 15
7 7
1 6
4 18
1 3
Enter the capacity of knapsack:- 15
The result vector is:- 1.000000 1.000000 1.000000 1.000000
1.000000 0.666667 0.000000
Maximum profit is:- 55.333332
|
No comments:
Post a Comment