#include
void Gknapsack(int [],int,int);
void main()
{
clrscr();
int i,w[30],p[30],m,n;
/* w array for weights.
p array for profits.
m stands for maximum capacity.
n stands for number od items.
i is counter.*/
cout<<"enter the number of items::";
cin>>n;
cout<
cout<
cin>>w[i];
cout<
cin>>p[i];
Gknapsack(w,m,n);
getch();
}
void Gknapsack(int w[],int m,int n)
{
float x[30];
int U=m;
for(int i=1;i<=n;i++)
x[i]=0;
for(i=1;i<=n;i++)
{
if(w[i]>U)
break;
x[i]=1;
U=U-w[i];
}
if(i<=n)
x[i]=(float)U/w[i];
cout<
cout<
No comments:
Post a Comment