zoukankan      html  css  js  c++  java
  • 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
    ",i);
        //system ("pause");
        return 0;
    }
  • 相关阅读:
    Mysql一些复杂的语句
    Tomcat部署记事
    [转]Java中的事务
    Junit单元测试笔记
    Mysql之执行计划
    当产品部署出现问题时
    CSS之绝对定位那些事
    CSS之浮动那些事
    Tomcat一些小事
    NEC的学习笔记
  • 原文地址:https://www.cnblogs.com/dyzll/p/5759449.html
Copyright © 2011-2022 走看看