#include<algorithm>#include<iostream>usingnamespacestd;constexprintN=105;intn,m,ans;structNode{inta,b;// a 代表时间,b 代表价值doublef;}node[N];booloperator<(Nodep,Nodeq){returnp.f>q.f;}intf(intt,intv){// 计算在当前时间下,剩余物品的最大价值inttot=0;for(inti=1;t+i<=n;i++)if(v>=node[t+i].a){v-=node[t+i].a;tot+=node[t+i].b;}elsereturn(int)(tot+v*node[t+i].f);returntot;}voidwork(intt,intp,intv){ans=max(ans,v);if(t>n)return;// 边界条件:只有n种物品if(f(t,p)+v>ans)work(t+1,p,v);// 最优性剪枝if(node[t].a<=p)work(t+1,p-node[t].a,v+node[t].b);// 可行性剪枝}intmain(){cin.tie(nullptr)->sync_with_stdio(false);cin>>m>>n;for(inti=1;i<=n;i++){cin>>node[i].a>>node[i].b;node[i].f=1.0*node[i].b/node[i].a;// f为性价比}sort(node+1,node+n+1);// 根据性价比排序work(1,m,0);cout<<ans<<'\n';return0;}
Last updated on this page:, Update history Found an error? Want to help improve? Edit this page on GitHub! Contributors to this page:OI-wiki All content on this page is provided under the terms of the CC BY-SA 4.0 and SATA license, additional terms may apply