A Question of Ingestion

时间限制: 1 Sec  内存限制: 128 MB
提交: 95  解决: 26
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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 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.

输出

Display the maximum number of calories Stan can consume.

样例输入

5 900
800 700 400 300 200

样例输出

2243

来源/分类

ecna2017

思路:

100的范围, 显然可以 n方 dp。

设计dp状态,dp(i,j)表示到第 i 天,连续吃了 j 天。然后状态瞎xx转移。

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=110;
ll dp[maxn][maxn],a[maxn],f[maxn];
ll n,m;int main(){scanf("%lld %lld",&n,&m);f[0]=m;for (int i=1; i<=n; i++) {scanf("%lld",&a[i]);f[i]=f[i-1]*2/3;dp[i][0]=min(a[i],m);}for (int i=1; i<=n; i++){for (int j=0; j<=n; j++){for (int k=1; k<=n && i+k<=n&&k<=2; k++)dp[i+k][j+2-k]=max(dp[i+k][j+2-k],dp[i][j]+min(f[j+2-k],a[i+k]));dp[i+3][0]=max(dp[i+3][0],dp[i][j]+min(a[i+3],m));}}ll ans=-1;for (int i=0; i<=n; i++)ans=max(ans,dp[n][i]);printf("%lld\n",ans);return 0;
}

View Code

转载于:https://www.cnblogs.com/acerkoo/p/9580561.html

A Question of Ingestion(Dp)相关推荐

  1. 求三角形最大面积(DP)

    求三角形最大面积(DP) 在OJ上奇迹般WA了:WA:70. Why? #include <iostream> #include <string.h> using namesp ...

  2. LeetCode 编辑距离 II(DP)

    1. 题目 给你两个单词 s 和 t,请你计算出将 s 转换成 t 所使用的最少操作数. 你可以对一个单词进行如下两种操作: 删除一个字符 替换一个字符 注意: 不允许插入操作 题目保证有解 示例: ...

  3. LeetCode 1220. 统计元音字母序列的数目(DP)

    文章目录 1. 题目 2. 解题 1. 题目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: - 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i ...

  4. LeetCode 265. 粉刷房子 II(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成 k 种颜色中的一种,你需要粉刷所有的房子并且使其相邻的两个房子颜色不能相同. 当然,因为市场上不同颜色油 ...

  5. LeetCode 256. 粉刷房子(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成红色.蓝色或者绿色这三种颜色中的一种,你需要粉刷所有的房子并且使其与相邻的两个房子颜色不能相同. 当然,因 ...

  6. LeetCode 1223. 掷骰子模拟(DP)

    1. 题目 有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数. 不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始 ...

  7. LeetCode 1155. 掷骰子的N种方法(DP)

    1. 题目 这里有 d 个一样的骰子,每个骰子上都有 f 个面,分别标号为 1, 2, -, f. 我们约定:掷骰子的得到总点数为各骰子面朝上的数字的总和. 如果需要掷出的总点数为 target,请你 ...

  8. LeetCode 1139. 最大的以 1 为边界的正方形(DP)

    1. 题目 给你一个由若干 0 和 1 组成的二维网格 grid,请你找出边界全部由 1 组成的最大 正方形 子网格,并返回该子网格中的元素数量.如果不存在,则返回 0. 示例 1: 输入:grid ...

  9. 程序员面试金典 - 面试题 17.23. 最大黑方阵(DP)

    1. 题目 给定一个方阵,其中每个单元(像素)非黑即白. 设计一个算法,找出 4 条边皆为黑色像素的最大子方阵. 返回一个数组 [r, c, size] ,其中 r, c 分别代表子方阵左上角的行号和 ...

  10. LeetCode 1406. 石子游戏 III(DP)

    1. 题目 Alice 和 Bob 用几堆石子在做游戏.几堆石子排成一行,每堆石子都对应一个得分,由数组 stoneValue 给出. Alice 和 Bob 轮流取石子,Alice 总是先开始.在每 ...

最新文章

  1. 读书笔记 - 《21世纪的管理挑战》
  2. Java填坑系列之SparseArray
  3. CentOS编译安装php扩展gd
  4. WebAPI返回数据类型
  5. Flink-java读取Kafka(转载+自己验证)
  6. string转成对象_详解Java I/O流(五),对象序列化
  7. 复习Python DB-API
  8. Webpack的代码分包Vue3中定义异步组件分包refs的使用
  9. php 织梦模板 防盗,织梦DedeCMS模板怎么防盗
  10. python 列表为空报错_对比几段代码,看看你是 Python 菜鸟还是老鸟
  11. SQLAlchemy 嵌套事务的解决方案
  12. 【网络原理】期末复习笔记 第一章 概述
  13. hdfs 创建用户和用户组_HDFS原理 | 一文读懂HDFS架构与设计
  14. LMDB内存映射型数据库
  15. python做生物信息学分析_Python从零开始第五章生物信息学①提取差异基因
  16. python代码实现自动点击屏幕
  17. 2019最新微信公众平台PHP开发搭建与揭秘(附代码)
  18. Emulator: Warning: Quick Boot / Snapshots not supported on this machine. A CPU with EPT + UG featur
  19. ZYNQ + Linux
  20. Linux jq 、vim以及LInux集群安装miniconda并配置虚拟环境(笔记)

热门文章

  1. tf.matrix_diag和tf.matrix_inverse的用法(tensorflow如何生成对角矩阵和求逆矩阵)
  2. 多项式计算的Horner 方法
  3. python dict key类型_Python——dict(自定义类作key)
  4. UVaOJ 12304 2D Geometry 110 in 1!
  5. 无线路由器DNS服务器异常,fast无线路由器dns异常的解决方法
  6. 红米充电短路 红米note3充电短路 无法充电
  7. no algorithm found for: 08000000h - 0800275bhno algorithm found for: 08000000h - XXXXXXXXH
  8. SSD,eMMC,UFS的区别
  9. openwrt 软路由负载均衡
  10. MSP430F149TIMER_A的连续计数模式