Treats for the Cows

P2858 [USACO06FEB] Treats for the Cows G/S 约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱。为此,约翰购置了 𝑁(1≤𝑁≤2000) 份美味的零食来卖给奶牛们。每天约翰售出一份零食。𝑉𝑖 的是从盒子顶端往下的第i份零食的初始价值。约翰告诉了你所有零食的初始价值,并希望你能帮他计算一下,在这些零食全被卖出后,他最多能得到多少钱。 阅读详情

Treats for the Cows

 Treats for the Cows
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  POJ 3186

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

The treats are interesting for many reasons:
  • The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can retrieve one treat from either end of his stash of treats.
  • Like fine wines and delicious cheeses, the treats improve with age and command greater prices.
  • The treats are not uniform: some are better and have higher intrinsic value. Treat i has value v(i) (1 <= v(i) <= 1000).
  • Cows pay more for treats that have aged longer: a cow will pay v(i)*a for a treat of age a.
Given the values v(i) of each of the treats lined up in order of the index i in their box, what is the greatest value FJ can receive for them if he orders their sale optimally? 

The first treat is sold on day 1 and has age a=1. Each subsequent day increases the age by 1.

Input

Line 1: A single integer, N 

Lines 2..N+1: Line i+1 contains the value of treat v(i)

Output

Line 1: The maximum revenue FJ can achieve by selling the treats

Sample Input

5
1
3
1
5
2

Sample Output

43

Hint

Explanation of the sample: 

Five treats. On the first day FJ can sell either treat #1 (value 1) or treat #5 (value 2). 

FJ sells the treats (values 1, 3, 1, 5, 2) in the following order of indices: 1, 5, 2, 3, 4, making 1x1 + 2x2 + 3x3 + 4x1 + 5x5 = 43.


本题是一个区间DP问题,如果我们按照常规思路的话,会无法确定最终状态,所以,我们可以逆向思维一下,让区间由内向外扩。首先我们每个元素都有可能是最后一次拿的,所以我们让dp[i][i]=v[i]*n。然后我们再遍历每一个可能的区间,每次取最优解,最后当区间扩到dp[1][n]的时候,我们认为结束,此时的dp[1][n]即为我们所求结果。状态转移方程为dp[i]=max{dp[i+1][j]+v[i]*(n-j+i),dp[i][j-1]+v[j]*(n-j+i)}.注意 :n-j+i为天数;i要逆序,j顺序。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[2005][2005];
int main()
{
    int n,v[2005];
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        dp[i][i]=v[i]*n;
    }
    for(int i=n-1;i>=1;i--)
    {
        for(int j=i+1;j<=n;j++)
        {
            dp[i][j]=max(dp[i+1][j]+v[i]*(n-j+i),dp[i][j-1]+v[j]*(n-j+i));
        }
    }
    printf("%d\n",dp[1][n]);
    return 0;
}

【无人机路径规划】基于强化学习实现多无人机路径规划 阅读详情

相关推荐

WinCC与施耐德PLC的Modbus TCP通信实战指南

本文详细解析了西门子WinCC与施耐德PLC通过Modbus TCP协议实现通信的完整实战流程。内容涵盖硬件网络配置、Modbus地址映射核心规则、WinCC驱动连接建立、变量创建及高级数据访问技巧,并提供了常见故障排查思路,帮助工程师高效解决跨品牌设备通信难题。

weixin_29194693的博客 1003

ACM题解——动态规划专题——treats

ACM题解——动态规划专题——奶牛食物的最大收益 题目描述 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 period time. The treat

Biangbangbing的博客 784

华为鸿蒙系统也能用!5分钟搞定谷歌三件套安装(附最新APK下载链接)

本文为华为鸿蒙系统用户提供了一份详尽的谷歌三件套(Google Play服务、商店及框架)手动安装指南。文章核心在于无需Root,通过ADB命令获取设备信息,并从可靠来源下载匹配版本的APK,按照正确顺序安装,从而解决海外应用依赖问题,实现5分钟快速部署。

c7d8e9的博客 6535

33. Treats for the Cows

FJ has purchased N (1 The treats are interesting for many reasons: The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ can

该博客暂停使用 418

利用Android系统漏洞实现后台弹窗(外弹)

关键:从 Android 8.0(API 26)开始,禁止使用 context.sendBroadcast() 发送隐式广播(即没有指定 setPackage() 或明确组件的广播)。demo核心代码展示利用Android显示系统和广播系统的漏洞实现在后台弹窗的功能,支持最新Android15,16版本。核心功能都是在so层去做,大量使用了jni反调, 如果要上架到应用市场,需要对代码做进一步混淆,加固以应对市场安全扫描。3,开启虚拟显示窗口,这是个透明像素窗口。5,可开启一个线程,调用这个外弹窗口。

2018,再出发~ 1316

Web3前沿技术的智能合约安全审计

随着Web3技术的快速发展,智能合约作为区块链应用的核心组件,其安全性问题日益突出。本文旨在系统性地介绍智能合约安全审计的技术体系,帮助开发者理解智能合约安全风险,掌握安全审计的方法论和工具链。智能合约安全的基本概念常见漏洞类型及其原理安全审计的技术方法实际审计案例分析安全审计工具和资源首先介绍基本概念和背景然后分析常见漏洞和安全风险接着详细讲解安全审计技术提供实际案例和代码示例最后讨论工具资源和未来趋势智能合约:运行在区块链上的自执行程序,代码即法律安全审计。

AI天才研究院 1547

8.24--练习赛D题--Treats for the cows(区间DP)

原题: FJ has purchased N (1 The treats are interesting for many reasons: The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any d

sdau164185的博客 370

Ascend开发包Acllite安装

设置环境变量,配置程序编译依赖的头文件,库文件路径。“$HOME/Ascend”请替换“Ascend-cann-toolkit”包的实际安装路径。将YOLOV7原始模型转换为适配昇腾310处理器的离线模型(*.om文件),放在model路径下。运行完成后,会在样例工程的out目录下生成推理后的图片,显示对比结果如下所示。可以使用以下两种方式下载,请选择其中一种进行源码准备。请从以下链接获取该样例的输入图片,放在data目录下。执行以下命令,执行编译脚本,开始样例编译。执行运行脚本,开始样例运行。

如果想成为中心,那么就到中心去吧。 318

(POJ - 3186)Treats for the Cows(区间DP)

题目链接:3186 -- Treats for the Cows 题意:给你n个已经排列好的数字,每次你可以取出最左端的数字或取出最右端的数字,一共n次取完。假设你第i次取的数字是x,你可以获得i*x的价值。你需要规划取数顺序,使获得的总价值之和最大。 分析:这道题容易错看成贪心题,每次选取当前可选择的最小值,这样的贪心思路是错误的。 下面进行正确思路的分析: 我们设dp[i][j]表示从左边取出i个从右边取出j个的所有情况中结果最大值,这个状态可以由两种状态转移过来,一种是dp[i-1][j],也

AC__dream的博客 461

基于DPCNN实现电商情感分析任务

下载链接项目中使用的模型是DPCNN,在模型中我们定义了三个组件,分别是embedding层,卷积层和全连接层。Embedding层:将每个词生成对应的嵌入向量,就是利用一个连续型向量来表示每个词卷积层:提取语句中的语义信息Linear层:将结果映射成2大小用于二分类,即正反面的概率。

优快云 精品推荐 1629

[Python] 如何使用 Python 调用 Dify 工作流服务实现自动化翻译

本文介绍了如何使用Python调用Dify的API实现文本翻译自动化。Dify作为AI开发平台,其工作流功能可执行文本处理、翻译等任务。选择Python调用Dify的优势在于职责划分清晰:Dify专注AI服务,Python处理文件操作等非AI任务。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 1097

寒假笔记·记忆化搜索

记忆化搜索 例题:P2858 [USACO06FEB]奶牛零食Treats for the Cows 原题地址 题目描述 FJ has purchased N (1 &amp;amp;amp;amp;amp;amp;amp;lt;= N &amp;amp;amp;amp;amp;amp;amp;lt;= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one

weixin_43918350的博客 378

【突变检验合集】含Pettitt突变检验等

突变检验方法合集

WW、forever的博客 3534

BZOJ1652: [Usaco2006 Feb]Treats for the Cows

1652: [Usaco2006 Feb]Treats for the Cows 水题不说 #include<cstdio> #include<algorithm> using namespace std; int n,Ans,a[2005],F[2005][2005]; int main(){ scanf("%d",&n); for(int i=1;i<...

XSamsara的博客 AFO 213

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ 3186 Treats for the Cows

POJ 3186 Treats for the Cows POJ入口:http://poj.org/problem?id=3186 AC代码 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typede...

恒治学 138

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

[POJ 3168 Treats for the Cows]区间dp

[POJ 3168 Treats for the Cows]区间dp分类:区间dp1. 题目链接[POJ 3168 Treats for the Cows]2. 题意描述有nn个美味排成一列,编号为1,2,...,n1,2,...,n,第ii个美味价值为viv_i。每次只能挑选两端的美味,第aa次挑选到第ii个美味,可获得价值vi∗av_i*a。求可以获得的最大的价值。3. 解题思路最简单的区间dp

Fighting! 531

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

题海拾贝:P2858 [USACO06FEB] Treats for the Cows G/S

【代码】题海拾贝:P2858 [USACO06FEB] Treats for the Cows G/S。

但凡的博客 421

P2858 [USACO06FEB]Treats for the Cows G/S (区间DP)

P2858 [USACO06FEB]Treats for the Cows G/S (区间DP) 题目传送门 思路: AC代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e3+5; int v[N],dp[N][N]; int main(){ int n; s...

Harris-H的博客 761

poj 3186 Treats for the Cows(区间dp)

Description FJ has purchased N (1 The treats are interesting for many reasons: The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On

ZAQ的博客 397

poj 3186 java_kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

Treats for the CowsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 7949Accepted: 4217DescriptionFJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving va...

weixin_29084111的博客 227

P2858 [USACO06FEB]Treats for the Cows G/S(区间dp)

P2858[USACO06FEB]Treats for the Cows G/Shttps://www.luogu.com.cn/problem/P2858 #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #in.

Ghostttttttiii的博客 366

POJ 3186 Treats for the Cows

FJ has purchased N (1 The treats are interesting for many reasons: The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On any day, FJ ca

樱花满地集于我心,楪舞纷飞祈愿相随 380

bzoj1652[Usaco2006 Feb]Treats for the Cows*

bzoj1652[Usaco2006 Feb]Treats for the Cows 题意: 管子里n个巧克力,第i个价值为ai。每天从左端点或右端点拿一个出来卖,收入为这个巧克力的价值*它是第几天卖出的。问最大价值。n≤2000 题解: dp:f[l][r]=max(f[l+1][r]+a[l]*(n-(r-l+1)+1),f[l][r-1]+a[r]*(n-(r-l+1)+1))。 ...

weixin_34227447的博客 89

Treats for the Cows(dp 简单)

Treats for the Cows 每种情况都考虑一下就好了 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int dp[2010][2010]; ...

百般回首曾经的相遇,留下的只是一缕残忆 1197

POJ - 3186 Treats for the Cows

Treats for the Cows 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

什么样的小孩 的博客 249

【O - Treats for the Cows】

思路: 新类型:区间dp。 dp[l][r] 代表在区间 [l,r] 内可以取到的最大值,注意,我们是从小到大逐步蚕食增大区间的,根据题意,可知在整个过程中是最后取本区间内的值。 注意初始化,枚举时先枚举长度,再根据长度枚举起点。 代码: 47ms 14560kB ​//47ms 14560kB #include <iostream> #include <algor...

Masker 250
上一篇: FatMouse's Speed
下一篇: 最短路 HDU 2122
Scott_Wong06
博客等级 码龄9年 5粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值