New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



KNAPSACK PROBLEM


Posted Date:     Total Responses: 0    Posted By: Rashina   Member Level: Gold   Points/Cash: 3   


#include
#include
const int MAX=30;
int mfk(int,int);
int max(int,int);
int profit[MAX];
int weight[MAX];
int v[MAX][MAX];
int n;
int M;
void main()
{
int j;
int optsol;
clrscr();
cout<<"\n KNAPSACK PROBLEM";

cout<<"\nenter the no. of objects:";
cin>>n;
cout<<"enter the weight OF THE OBJECT ONE BY ONE ::";
for(int i=1;i<=n;i++)
{
cout<<"\n";
cout<<"[";
cout< cout<<"] :: " ;
cin>>weight[i];
}
cout<<"enter the profit one by one :: ";
for(i=1;i<=n;i++)
{
cout<<"\n";
cout<<"[";
cout< cout<<"] :: " ;

cin>>profit[i];
}
cout<<"enter the total knapsack capacity:";
cin>>M;
for(i=0;i<=M;i++)
v[0][i]=0;
for(i=0;i<=n;i++)
v[i][0]=0;
for(i=1;i<=n;i++)
for(j=1;j<=M;j++)
v[i][j]=-1;
cout< optsol=mfk(n,M);
cout<<"optimal sol::"< getch();
}
int mfk(int i,int j)
{
int p;
if(v[i][j]==-1)
{
if(j p=mfk(i-1,j);
else
p=max(mfk(i-1,j),mfk(i-1,j-weight[i])+profit[i]);
v[i][j]=p;
}
return v[i][j];
}
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}


Project Feedbacks


No feedbacks found. Be the first to respond and make money from revenue sharing program.

Post Feedback
You must Sign In to post a feedback.
Next Project: Define a structure data type named 'date' containing three integer members day, month and year. Deve
Previous Project: STACK

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.