聖誕節來臨了,在城市A中聖誕老人准備分發糖果,現在有多箱不同的糖果,每箱糖果有自己的價值和重量,每箱糖果都可以拆分成任意散裝組合帶走。聖誕老人的馴鹿最多只能承受一定重量的糖果,請問聖誕老人最多能帶走多大價值的糖果。
4 15 100 4 412 8 266 7 591 2
1193.0
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int times;
int weight;
int UseNu=0;
double AllValue=0;
int AllWeight=0;
cin>>times>>weight;
UseNu=weight;
struct MyGift{
int Value;
int Weit;
double perVal;
};
struct MyGift Gift[times];
struct MyGift Temp={0,0,0
};
for(int i=0;i<times;i++) cin="">>Gift[i].Value>>Gift[i].Weit;
Gift[i].perVal=(double)(Gift[i].Value)/(double)(Gift[i].Weit);
AllWeight+=Gift[i].Weit;
AllValue+=Gift[i].Value;
}
for(int j=0;j<times;j++) int="" h="1;h<times;h++)" temp="Gift[h-1];" return="" allvalue="0;" z="0;z<times;z++)" usenu-="Gift[z].Weit;" pre=""><p>
</p>
</times;j++)></times;i++)></iostream></stdio.h>