ad

Sunday, 8 February 2015

program to implement fractional knapsack problem using greedy method in cpp

//program to implement knapsack problem using greedy method
#include < conio.h >
#include < iostream.h >
class knapsack
{
 int n,m,*p,*w;
 float *x,*pw;
 public:
  knapsack()
  {
   clrscr();
   cout<<"\n\t\tKNAPSACK PROBLEM\n";
   int i;
   cout<<"\nEnter the number of objects : ";
   cin>>n;
   p=new int[n];
   w=new int[n];
   pw=new float[n];
   x=new float[n];
   for(i=0;i>m;
 cout<<"\nEnter the profit of the elements : ";
 for(i=0;i>p[i];
 cout<<"\nEnter the weights of the objects : ";
 for(i=0;i>w[i];
 for(i=0;iv)
     break;
   else
   {
   x[i]=1.0;
   v=v-w[i];
   }
  }
  if(i

No comments:

Post a Comment