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- ...
随机推荐
- git config文件总结及git alias配置
1. 文件位置 mac /etc/.gitconfig 系统级~/.gitconifg 用户级(覆盖系统级) windows C:\Users\$user\.gitconfig 当前项目下 .git/ ...
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
- fresco的使用教程
1.加载依赖 api 'org.xutils:xutils:3.5.0' 2.创建一个myapplication public class MyApplication extends Applicat ...
- ansible+docker
1.准备镜像: 1007 docker run -itd --name client2 ff37bc5ab732 1008 docker run -itd --name client ff37bc5a ...
- Android百度定位地图使用--文章集锦
Android百度定位API使用方法 Android百度地图开发(一)之初体验 AndroidNote013.在百度地图上画出轨迹 Android学习笔记之百度地图(分条目覆盖物:ItemizedOv ...
- nginx解决超长请求串(413 request Entity too Large错误解决办法)
<div class="hide-article-box text-center" style="display: block;"> <a c ...
- HDU1016 素数环---(dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1016 Sample Input 6 8 Sample Output Case 1: 1 4 3 2 5 6 ...
- 汕头市队赛 SRM16
T3 C-2 SRM 16 描述 给一个数列,给出两种数字, 询问在多少个非空区间中这两种数字出现次数相同. 输入格式 第一行:一个数字n,q,n表示数列长度,q表示q组询问 第二行n个数字表示数列A ...
- xcode自动打ipa包脚本
http://blog.csdn.net/ccf0703/article/details/7999112 文章首发地址:http://webfrogs.github.com/IOS/2012/09/1 ...
- linux驱动基础系列--linux rtc子系统
前言 linux驱动子系统太多了,连时钟也搞了个子系统,这导致一般的时钟芯片的驱动也会涉及到至少2个子系统,一个是时钟芯片接口子系统(比如I2c接口的时钟芯片),一个是内核给所有时钟芯片提供的rtc子 ...