int main(void)
{
cout<<"|--------运用贪心法解背包问题---------|"<<endl;
cout<<"|-------------------------------------|"<<endl;
int i,j,n;
float M;
goodinfo *goods; //定义一个指针
cout<<"press <1> to run the program"<<endl;
cout<<"press <0> to exit"<<endl;
cin>>j;
while(j)
{
cout<<"请输入物品的总数量:";
cin>>n;
goods=new struct goodinfo [n+1];
cout<<"请输入背包的最大容量:";
cin>>M;
cout<<endl;
for(i=1;i<=n;i++)
{
goods[i].flag=i;
cout<<"请输入第"<<i<<"件物品的重量:";
cin>>goods[i].w;
cout<<"请输入第"<<i<<"件物品的效益:";
cin>>goods[i].p;
goods[i].p=goods[i].p/goods[i].w; //得出物品的效益,重量比
cout<<endl;
}
Insertionsort(goods,n);
bag(goods,M,n);
cout<<"press <1> to run agian"<<endl;
cout<<"press <0> to exit"<<endl;
cin>>j;
}
system("pause");
return 0;
}
------解决方案--------------------
明显的是C++