#include#include using namespace std; struct Goods{ int weight; int value; double per;//单位重量的价值 double load;//装多少权重 }; //定义sort函数比较器 int compare(Goods const&a,Goods const&b){ if(a.per>b.per) return 1; else return 0; } //贪心算法 void Greedy(Goods g[],int good_number,int content){ for(int i=0;i 0){ g[i].load=(double)content/g[i].weight; cout< >n; cout<<"请输入背包大小"< >bag; Goods gs[n+1]; cout<<"请依次输入每种货物的重量和价值"< >gs[i].weight;