Fruit Feast(暴力)(动态规划)
Fruit Feast
时间限制: 1 Sec 内存限制: 64 MB
提交: 64 解决: 18
[提交][状态][讨论版]
题目描述
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!
输入
输出
样例输入
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>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
ll sum=;
int n,m;
int vis[N];
int maxn=;
struct man
{
int num,use;
};
int main()
{
int a,b;
memset(vis,,sizeof(vis));
scanf("%d%d%d",&n,&a,&b);
queue<man>q;
man A;A.num=a;A.use=;
man B;B.num=b;B.use=;
q.push(A);q.push(B);
vis[a]=;vis[b]=;
while(!q.empty()){
man t=q.front();
q.pop();
if(t.num+a>n)maxn=max(maxn,t.num);
if(t.num+a<=n&&vis[t.num+a]==){
vis[t.num+a]=;
man k;k.num=t.num+a;k.use=t.use;
q.push(k);
}
if(t.num+b>n)maxn=max(maxn,t.num);
if(t.num+b<=n&&vis[t.num+b]==){
vis[t.num+b]=;
man k;k.num=t.num+b;k.use=t.use;
q.push(k);
}
if(t.use==&&vis[t.num/]==){
vis[t.num/]=;
man k;k.num=t.num/;k.use=;
q.push(k);
}
}
printf("%d\n",maxn);
return ;
}
暴力
#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>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
ll sum=;
int n,m;
int vis[N];
int maxn=;
int dp[N];
int main()
{
int a,b;
scanf("%d%d%d",&n,&a,&b);
dp[]=;
for(int i=a;i<=n;i++)dp[i]|=dp[i-a];
for(int i=b;i<=n;i++)dp[i]|=dp[i-b];
for(int i=;i<=n;i++)dp[i/]|=dp[i];
for(int i=a;i<=n;i++)dp[i]|=dp[i-a];
for(int i=b;i<=n;i++)dp[i]|=dp[i-b];
for(a =n;dp[a]==;a--);
cout<<a<<endl;
return ;
}
动态规划
Fruit Feast(暴力)(动态规划)的更多相关文章
- USACO 2015 December Contest, Gold Problem 2. Fruit Feast
Problem 2. Fruit Feast 很简单的智商题(因为碰巧脑出来了所以简单一,一 原题: Bessie has broken into Farmer John's house again! ...
- Fruit Feast
Fruit Feast 题目描述 Bessie has broken into Farmer John's house again! She has discovered a pile of lemo ...
- bzoj4393: [Usaco2015 Dec]Fruit Feast
题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...
- P4817 [USACO15DEC]Fruit Feast 水果盛宴
P4817 [USACO15DEC]Fruit Feast 水果盛宴 现在Bessie的饱食度为 00 ,她每吃一个橙子,饱食度就会增加 AA :每吃一个柠檬,饱食度就会增加 BB .Bessie还有 ...
- BZOJ 4393: [Usaco2015 Dec]Fruit Feast
DP #include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf(&q ...
- P4817 Fruit Feast G
最开始拿到这道题的时候,题目中其实只规定了两种水果的饱食度,可以理解成价值或是重量,在不超过T的情况求最大值.第一眼看过去感觉就是装箱问题(背包),只不过这道题用的是完全背包,但是考虑到喝水的情况,做 ...
- bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)
听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- dp式子100个……
1. 资源问题1-----机器分配问题F[I,j]:=max(f[i-1,k]+w[i,j-k]) 2. 资源问题2------01背包问题F[I,j]:=max(f[i- ...
随机推荐
- 【题解】NOIP2016愤怒的小鸟
一眼n<=18状压dp……方程什么的都很显然,枚举两只小鸟,再将这条抛物线上的小鸟抓出来就好啦.只是这样O(n^3)的dp必然是要TLE的,我一开始这样交上去显然跑得巨慢无比,后来转念一想:面对 ...
- [bzoj4071] [Apio2015]巴邻旁之桥
Description 一条东西走向的穆西河将巴邻旁市一分为二,分割成了区域 A 和区域 B. 每一块区域沿着河岸都建了恰好 1000000001 栋的建筑,每条岸边的建筑都从 0 编号到 10000 ...
- hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)
hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...
- Notice : brew install php70
To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module ...
- yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY 博客分类: linux 三种解决方案 我采取第三种方案解决的 第一种: linu ...
- Windows下查看某个端口被哪个服务占用
1.查看某个端口是否被占用 打开命令行,输入:netstat -ano | findstr "3306" 2.查看端口被哪个服务占用 tasklist | findstr “PID ...
- 转:强化学习(Reinforcement Learning)
机器学习算法大致可以分为三种: 1. 监督学习(如回归,分类) 2. 非监督学习(如聚类,降维) 3. 增强学习 什么是增强学习呢? 增强学习(reinforcementlearning, RL)又叫 ...
- Flex UI刷新后保持DataGrid中的ScrollBar的位置不变
这是之前我发的一个贴子问题描述:http://q.cnblogs.com/q/53469/
- 51nod 1040 最大公约数之和
给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 Input 1个数N(N <= ...
- DotNETCore 学习笔记 配置
Configuration var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(); var config ...