码迷,mamicode.com
首页 > 其他好文 > 详细

Fruit Feast

时间:2016-08-11 06:21:19      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

Fruit Feast

标签:

原文地址:http://www.cnblogs.com/dyzll/p/5759449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!