gym101673G A Question of Ingestion


A Question of Ingestion
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
ECNA 2017 Problem G: A Question of Ingestion 13
Sample Input 2 Sample Output 2
5 900
800 700 40 300 200
1900

 

 

一、题目地址

点我传送

 

二、大致题意

  给出n天,有一个饭量m。若连续吃饭 j 天则,每次能吃的量是m乘以(2/3)^ j 。或者你可以选择中途休息,若休息1天,则减少一个 j 次的2/3 。若连续休息两天,则下一次又可以吃 m 的量。

  第二行给出的是当天能得到的最多的摄入量。你在当天得到的能量不能超出这个上限。

询问最后能得到最大的能量总和。

 

三、思路

  dp[ i ][ j ]来记录在第 i 天,连续摄入第 j 天时能得到的总量的最大值。dp[ i ][ j ]的值要么是前一天选择吃饭转移来的,或者是前一天没有吃饭转移过来的。需要注意的是dp[ i ][ 1 ]可能是大前天转移过来的,这表示中间的两天选择不吃饭。

 

四、代码

#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;


int n, m;
int a[105];
int dp[105][105];
int mul[105];
int main()
{
	scanf("%d %d", &n, &m); 
	mul[1] = m; for (int i = 2; i <= 100; i++)mul[i] = mul[i - 1] * 2 / 3;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		for (int j = 0; j <= n; j++)dp[i][j] = 0;
	}
	dp[1][0] = 0;
	dp[1][1] = min(a[1], m);
	dp[2][1] = min(a[2], m);
	dp[2][2] = dp[1][1] + min(a[2], mul[2]);
	for (int i = 3; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			dp[i][j] = max(dp[i - 1][max(j - 1, 0)] + min(a[i], mul[j]), dp[i - 2][j]+ min(a[i], mul[j]));
		}
		int maxx = 0;
		for (int k = 0; k <= i - 3; k++)
			maxx = max(maxx, dp[i - 3][k]);
		dp[i][1] = max(dp[i][1], maxx + min(m, a[i]));
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)ans = max(ans, dp[n][i]);
	cout << ans << endl;
	getchar();
	getchar();
}
/*
3 900
1 900 1
*/

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自2020年以来,自动驾驶汽车(Autonomous Vehicle)在这一领域取得了显著进展。 自动驾驶汽车通过使用先进的传感技术,如雷达、激光雷达和摄像头,以及深度学习和人工智能算法,实现了车辆的自主驾驶。它们能够感知周围环境,了解道路状况,并做出相应的决策和行驶动作,从而实现无需人类操控的车辆行驶。 自动驾驶汽车在2020年迅速崭露头角。它们的技术日益成熟,不断的实验和测试表明其在安全性和性能方面已经取得了显著的突破。虽然仍然存在一些挑战,比如在复杂城市环境中导航和处理紧急情况,但这些问题正经过不断的研究和改进来得以解决。 在未来,自动驾驶汽车有望在各个领域发挥重要作用。首先,它们将可以提高道路交通的安全性。由于自动驾驶车辆不受人类司机的疲劳、分心和驾驶误差的限制,它们的驾驶能力更为稳定和准确。其次,自动驾驶汽车还能够提高交通效率。通过与其他车辆实时通信和协同,它们可以避免交通堵塞和减少事故发生,从而减少交通拥堵和行车时间成本。 此外,自动驾驶汽车也将为交通出行带来便利和舒适性。乘客可以更轻松地进行其他活动,如工作、休息或娱乐,而不必担心驾驶问题。老年人和残障人士也将能够自由独立地出行,提高他们的生活质量。 综上所述,作为2020年的重要趋势,自动驾驶汽车具有广阔的应用前景。通过不断的创新和发展,它们将在道路交通安全、交通效率和出行体验方面取得进一步的提升。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值