这题有两个简单的做法:贪心和暴力
我这里介绍一下暴力的做法
我们对于鸡肉和牛肉进行枚举,如果是可行的情况就更新答案
具体看代码吧:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #include<bits/stdc++.h> using namespace std; int t; long long b,p,f,h,c; int main(){ scanf("%d",&t); while(t--){ cin>>b>>p>>f>>h>>c; long long ans=0; for (int i=0;i<=p;i++) for (int j=0;j<=f;j++)if(((i+j)*2)<=b)ans=max(ans,i*h+j*c); cout<<ans<<endl; } }
|