首页 > 其他分享 >ECNA 2017 Problem G: A Question of Ingestion DP

ECNA 2017 Problem G: A Question of Ingestion DP

时间:2023-04-24 23:02:56浏览次数:38  
标签:hour int calories Question Ingestion 2017 include eat he

Stan Ford is a typical college graduate student, meaning that one of the most important things on his mind
is where his next meal will be. Fortune has smiled on him as he’s been invited to a multi-course barbecue
put on by some of the corporate sponsors of his research team, where each course lasts exactly one hour.
Stan is a bit of an analytical type and has determined that his eating pattern over a set of consecutive hours
is always very consistent. In the first hour, he can eat up to m calories (where m depends on factors such
as stress, bio-rhythms, position of the planets, etc.), but that amount goes down by a factor of two-thirds
each consecutive hour afterwards (always truncating in cases of fractions of a calorie). However, if he stops
eating for one hour, the next hour he can eat at the same rate as he did before he stopped. So, for example,
if m = 900 and he ate for five consecutive hours, the most he could eat each of those hours would be 900,
600, 400, 266 and 177 calories, respectively. If, however, he didn’t eat in the third hour, he could then eat
900, 600, 0, 600 and 400 calories in each of those hours. Furthermore, if Stan can refrain from eating for two
hours, then the hour after that he’s capable of eating m calories again. In the example above, if Stan didn’t
eat during the third and fourth hours, then he could consume 900, 600, 0, 0 and 900 calories.
Stan is waiting to hear what will be served each hour of the barbecue as he realizes that the menu will
determine when and how often he should refrain from eating. For example, if the barbecue lasts 5 hours and
the courses served each hour have calories 800, 700, 400, 300, 200 then the best strategy when m = 900 is
to eat every hour for a total consumption of 800 + 600 + 400 + 266 + 177 = 2 243 calories. If however, the
third course is reduced from 400 calories to 40 calories (some low-calorie celery dish), then the best strategy
is to not eat during the third hour — this results in a total consumption of 1 900 calories.
The prospect of all this upcoming food has got Stan so frazzled he can’t think straight. Given the number of
courses and the number of calories for each course, can you determine the maximum amount of calories Stan
can eat?
Input
Input starts with a line containing two positive integers n m (n ≤ 100, m ≤ 20 000) indicating the number
of courses and the number of calories Stan can eat in the first hour, respectively. The next line contains n
positive integers indicating the number of calories for each course.
Output
Display the maximum number of calories Stan can consume.
Sample Input 1 Sample Output 1
5 900
800 700 400 300 200
2243

考虑dp[ i ][ j ]表示准备吃第i 个食物,前面已经吃了 j 个食物的决策情况,然后枚举中途休息的情况即可
一道不错的dp题

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<sstream>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 600005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-7
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    a = a % mod;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}

int n, m;
int a[maxn];
int dp[200][200];
int b[200];
int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    int i, j;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int maxx = -inf;
    b[0] = m;
    for (i = 1; i <= 200; i++)
        b[i] = b[i - 1] * 2 / 3;
    for (i = 1; i <= n; i++) {
        dp[i][0] = min(a[i], b[0]);
    }
    for (i = 1; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            for (int k = 1; k <= n && k + i <= n&&k<=2; k++) {
                dp[i + k][j + 2 - k] = max(dp[i + k][j + 2 - k], dp[i][j] + min(a[i + k], b[j + 2 - k]));
            }
            dp[i + 3][0] = max(dp[i + 3][0], dp[i][j] + min(m, a[i + 3]));
        }
    }
    for (i = 0; i <= n; i++) {
        maxx = max(maxx, dp[n][i]);
    }
    cout << maxx << endl;
}

标签:hour,int,calories,Question,Ingestion,2017,include,eat,he
From: https://blog.51cto.com/u_15657999/6222004

相关文章

  • Nordic Collegiate Programming Contest (NCPC) 2017 C 在线查询,更新
    Onehundredyearsfromnow,in2117,theInternationalCollegiateProgrammingContest(ofwhichtheNCPCisapart)hasexpandedsignificantlyanditisnowtheGalacticCollegiateProgrammingContest(GCPC).Thisyeartherearenteamsinthecontest.T......
  • The 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
    ThetunnelsofCuChiareanimmensenetworkofundergroundtunnelsconnectingroomslocatedintheCuChiDistrictofHoChiMinhCity.TheCuChitunnelswerethelocationofseveralmilitarycampaignsinthe1960s.Nowadays,itisapopulartouristdes......
  • 【提示学习】Exploiting Cloze Questions for Few Shot Text Classification and Natu
    论文信息名称内容论文标题ExploitingClozeQuestionsforFewShotTextClassificationandNaturalLanguageInference论文地址https://arxiv.org/abs/2001.07676研究领域NLP,文本分类,提示学习,PET提出模型PET(Pattern-ExploitingTraining)来源EACL2021阅读摘要  目前......
  • 为什么2017年之后操作系统仍将扮演重要角色?
    操作系统的历史虽然不像计算科学那么久远,但却也已经拥有相当可观的发展历程。大型机客户于上世纪五十年代末编写了第一批操作系统,这些系统直到数十年后的今天仍拥有相当的知名度——其中包括来自IBM公司的OS/360以及贝尔实验室打造的Unix。在可预期的未来,操作系统仍将继续......
  • 为什么2017年之后操作系统仍将扮演重要角色?
    操作系统的历史虽然不像计算科学那么久远,但却也已经拥有相当可观的发展历程。大型机客户于上世纪五十年代末编写了第一批操作系统,这些系统直到数十年后的今天仍拥有相当的知名度——其中包括来自IBM公司的OS/360以及贝尔实验室打造的Unix。在可预期的未来,操作系统仍将继续......
  • 为什么2017年之后操作系统仍将扮演重要角色?
    操作系统的历史虽然不像计算科学那么久远,但却也已经拥有相当可观的发展历程。大型机客户于上世纪五十年代末编写了第一批操作系统,这些系统直到数十年后的今天仍拥有相当的知名度——其中包括来自IBM公司的OS/360以及贝尔实验室打造的Unix。在可预期的未来,操作系统仍将继续......
  • 【230417-1】三种方法解方程:(x-2017)(x-2021)=12
    ......
  • Linux 基金会发布 2017 最佳 Linux 发行名单
    Linux 基金会官网Linux.com近日发布了一篇名为“2017年最佳Linux发行版”的文章,并表示这些是从数百个发行版中发现的最好的Linux发行版。1、最佳系统管理员发行版:ParrotLinux2、最近轻量级发行版:LXLE3、最佳桌面发行版:ElementaryOS4、最佳验证发行版:Gentoo......
  • Linux 基金会发布 2017 最佳 Linux 发行名单
    Linux 基金会官网Linux.com近日发布了一篇名为“2017年最佳Linux发行版”的文章,并表示这些是从数百个发行版中发现的最好的Linux发行版。1、最佳系统管理员发行版:ParrotLinux2、最近轻量级发行版:LXLE3、最佳桌面发行版:ElementaryOS4、最佳验证发行版:Gentoo......
  • Linux 基金会发布 2017 最佳 Linux 发行名单
    Linux 基金会官网Linux.com近日发布了一篇名为“2017年最佳Linux发行版”的文章,并表示这些是从数百个发行版中发现的最好的Linux发行版。1、最佳系统管理员发行版:ParrotLinux2、最近轻量级发行版:LXLE3、最佳桌面发行版:ElementaryOS4、最佳验证发行版:Gentoo......