bzoj 4393 Usaco Fruit Feast

题目很明显的一道dp题目。

方程也不难推 dp[i][0]表示饱食度为i没喝水  dp[i][1]表示当前饱食度为i已经喝了水

#include <cstdio>
#include <algorithm>
using namespace std;

int t,a,b,Max;
bool dp[5000055][2];

int main(){
    scanf("%d%d%d",&t,&a,&b);
    dp[0][0]=1;
    for(int i=0;i<=t;i++){
        if(dp[i][0]){
            if(a+i<=t) dp[a+i][0]=1;
            if(b+i<=t) dp[b+i][0]=1;
            dp[i/2][1]=1;
        }
    }
    for(int i=0;i<=t;i++){
        if(dp[i][1]){
            if(a+i<=t) dp[a+i][1]=1,Max=max(Max,a+i);
            if(b+i<=t) dp[b+i][1]=1,Max=max(Max,b+i);
        }
    }
    printf("%d\n",Max);
    return 0;
}
时间: 2024-11-06 09:20:39

bzoj 4393 Usaco Fruit Feast的相关文章

bzoj4393: [Usaco2015 Dec]Fruit Feast

题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫就可以了TAT #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s

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 maxi

Fruit Feast(暴力)(动态规划)

Fruit Feast 时间限制: 1 Sec  内存限制: 64 MB提交: 64  解决: 18[提交][状态][讨论版] 题目描述 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 dete

[BZOJ 1652][USACO 06FEB]Treats for the Cows 题解(区间DP)

[BZOJ 1652][USACO 06FEB]Treats for the Cows Description FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a given

BZOJ 4393 Fruit Feast

沉迷刷水无法自拔. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5005000 using namespace std; int t,a,b; bool vis[maxn]; int main() { scanf("%d%d%d",&t,&a,&b); vis[0]=true; for

bzoj 3298: [USACO 2011Open]cow checkers -- 数学

3298: [USACO 2011Open]cow checkers Time Limit: 10 Sec  Memory Limit: 128 MB Description 一天,Besssie准备和FJ挑战奶牛跳棋游戏.这个游戏上在一个M*N(1<=M<=1,000,000;1<=N<=1,000,000)的棋盘上, 这个棋盘上在(x,y)(0<=x棋盘的左下角是(0,0)坐标,棋盘的右上角是坐标(M-1,N-1). Bessie每次都是第一个移动棋子,然后Bessie与

BZOJ 1617 Usaco River Crossing

一开始还以为是贪心,结果WA了一发. 才想到这是一个DP题目,子问题就是运送第i头牛时的最小花费. 那么转移方程也好表示. sum[i]表示前缀和  sum[0]表示单独一个人过河的时间m dp[i]=min(dp[i],dp[j]+sum[i-j]+sum[0]) #include <cstdio> #include <algorithm> #include <cstring> using std::min; int n,tot; int a[5005],dp[500

BZOJ 1602 Usaco 牧场行走

LCA的模板题目,今天才发现自己其实对LCA这个算法一点都没领悟.之前一直是在套模板,所以今天的主要目标就是学习一下tarjan算法求LCA,顺便刷点LCA的相关习题来加强理解~ 1 #include <cstdio> 2 #include <algorithm> 3   4 int dis[1005],head[2333],fa[1100][21],deep[1005]; 5 int Count,n,q; 6   7   8 struct node{ 9     int v,ne

BZOJ 1672 Usaco 2005 Dec Cleaning Shifts 清理牛棚 动态规划

题目大意:有一些牛,他们的牛舍需要被打扫.有N(N <= 10000)头牛愿意打扫,从时间S到时间T,需要花费一些金钱.问若要每时每刻都有牛在打扫,至少需要花多少钱. 思路:1w的数据量不算很大,再加上时限5s,就n^2动归来做. 将牛按时间段的开始排序. 设f[i]为若取第i头牛打扫,到这头牛结束的时间最小花费是多少. 则    f[i] = min(f[i],f[j] + cost[i])  (f[i].st <= f[j].ed + 1) 最后是初值和答案的问题.由于题目中说每时每刻都有