背包--nkoj3609【USACO 2015 Dec Gold】Fruit Feast

来源:互联网 发布:利用php漏洞进行提权 编辑:程序博客网 时间:2024/06/05 11:35

【USACO 2015 Dec Gold】Fruit Feast

Description

Bessie has broken into Farmer John's house again! She has discovered a pile of lemons and a pile of oranges in the kitchen (effectively an unlimited number of each), and she is determined to eat as much as possible. 
Bessie has a maximum fullness of T (1≤T≤5,000,000). Eating an orange increases her fullness by A, and eating a lemon increases her fullness by B (1≤A,B≤T). Additionally, if she wants, Bessie can drink water at most one time, which will instantly decrease her fullness by half (and will round down). 
Help Bessie determine the maximum fullness she can achieve! 

贝西正在搞破坏,她在厨房里发现了一堆柠檬派和一堆橘子派,打算尽量多吃一点。 
贝西能够达到的最大饱度为T(1≤T≤5,000,000)。每一份橘子派会增加A的饱度,每一份柠檬派会增加B的饱度(1≤A,B≤T)。她可以在吃的过程中至多喝一次水,喝水之后她的饱度会减半(向下取整)。 
帮贝西算出她能够达到的最大饱度。 

Input

The first (and only) line has three integers T, A, and B. 

第一行三个整数T,A,B。 

Output

A single integer, representing the maximum fullness Bessie can achieve. 

输出一个整数,表示贝西可以达到的最大饱度。 

Sample Input

8 5 6

Sample Output

8

水题:不解释,背包背包

#include<cstdio>#include<iostream>#include<algorithm>#include<queue>#include<stack>using namespace std;bool f[5000005];int w[3];int main(){int t,a,b,i,j;scanf("%d%d%d",&t,&a,&b);if(t%a==0||t%b==0){cout<<t;return 0;}w[1]=a;w[2]=b;f[0]=true;for(i=1;i<=2;i++){for(j=w[i];j<=t;j++){if(f[j-w[i]])f[j]=true;}}if(f[t]){cout<<t;return 0;}else{for(i=1;i<=t;i++){if(f[i])f[i/2]=true;}f[0]=false;for(i=1;i<=2;i++){for(j=w[i];j<=t;j++){if(f[j-w[i]])f[j]=true;}}}for(i=t;i>=0;i--){if(f[i]){cout<<i<<endl;return 0;}}}


0 0
原创粉丝点击