Fruit Feast

Fruit Feast

题目描述

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!

输入

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

输出

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

样例输入

8 5 6

样例输出

8
分析:完全背包,注意喝水时的更新;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define ll long long
#define pi acos(-1.0)
const int maxn=5e6+10;
const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q,ll mo){ll f=1;while(q){if(q&1)f=f*p%mo;p=p*p%mo;q>>=1;}return f;}
int n,m,k,t,a,b,dp[maxn];
int main()
{
    int i,j;
    scanf("%d%d%d",&n,&a,&b);
    dp[0]=1;
    for(i=a;i<=n;i++)dp[i]|=dp[i-a];
    for(i=b;i<=n;i++)dp[i]|=dp[i-b];
    for(i=0;i<=n;i++)dp[i/2]|=dp[i];
    for(i=a;i<=n;i++)dp[i]|=dp[i-a];
    for(i=b;i<=n;i++)dp[i]|=dp[i-b];
    for(i=n;dp[i]==0;i--);
    printf("%d\n",i);
    //system ("pause");
    return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5759449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值