Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Greedy Knapsack Algorithm (code In C++)

DZone's Guide to

Greedy Knapsack Algorithm (code In C++)

· Mobile Zone
Free Resource

Launching an app doesn’t need to be daunting. Whether you’re just getting started or need a refresher on mobile app testing best practices, this guide is your resource! Brought to you in partnership with Perfecto

// Greedy Knapsack


/*Greedy Knapsack Program
Source code created by S.Kaarthikeyan from 
Computer Technology And Application Department from 
Coimbatore Institute of Technology
*/

# include 

int w[10],p[10],p_no[10],n,m;
float pwr[10];

template 
void swap(T *a,int i,int j)
{
T temp;
temp=a[j];
a[j]=a[i];
a[i]=temp;
return;
}

void line()
{
coutm;
cout>n;
coutw[i];
cout>p[i];
pwr[i]=(float)p[i]/w[i];
}
display();
for(i=0;i

Keep up with the latest DevTest Jargon with the latest Mobile DevTest Dictionary. Brought to you in partnership with Perfecto.

Topics:
c+

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}