15-11-2012, 04:31 PM
BACKTRACKING ALGORITHM – KNAPSACK PROBLEM
BACKTRACKING ALGORITHM – KNAPSACK PROBLEM.docx (Size: 13.53 KB / Downloads: 28)
Algorithm:
Step 1: Declare the variables, array size and functions
Step 2: Get the value of number of objects and size of knapsack
Step 3: Enter weight and profit of objects
Step 4: Assign the initial values
Step 5: Call the necessary function and display the profit
Step 6: End of program
Coding:
#include<stdio.h>
#include<conio.h>
int c,cl,n,i,j,k;
int q[10],x[10][10],w[10],p[10],max;
void get();
void knapsack();
void display();
void get()
{
printf("Enter the number of objects ::");
scanf("%d",&n);
printf("Enter the size of knapsack :: ");
scanf("%d",&c);