poj 3186 Treats for the Cows(区间dp)

Python爬虫实战:携程旅游攻略爬取全流程解析(动态接口+反爬破解+异步爬取) 本文介绍了携程旅游攻略的爬取全流程,涵盖静态和动态页面抓取、异步请求、高级反爬策略以及数据存储和简单分析。增加用户评论和评分抓取结合NLP分析攻略文本情感与关键词建立旅游推荐系统自动化代理IP池和验证码识别模块。 阅读详情
Treats for the Cows
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5172 Accepted: 2697

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.

Source

USACO 2006 February Gold & Silver

题意:给出的一系列的数字,可以看成一个双向队列,每次只能从队首或者队尾出队,第n个出队就拿这个数乘以n,最后将和加起来,求最大和


/*
    dp[i][j]记录取i-j能获得的最大价值
    从取最后一个开始想,取最后一个i是a[i]*n, 上次取得就是dp[i-1][i]或dp[i][i+1]
    状态转移方程:dp[i][j] = max(dp[i+1][j]+(n-k)*a[i], dp[i][j-1]+(n-k)*a[j]),  (k是ij区间长度)
*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 2005;
int a[maxn], dp[maxn][maxn];
int main(void)
{
    int n;
    while(cin >> n)
    {
        memset(dp, 0, sizeof(dp));
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]), dp[i][i] = n*a[i];
        for(int k = 1; k < n; k++)
            for(int i = 1; i+k <= n; i++)
            {
                int j = i+k;
                dp[i][j] = max(dp[i+1][j]+(n-k)*a[i], dp[i][j-1]+(n-k)*a[j]);
            }
        printf("%d\n", dp[1][n]);
    }
    return 0;
}



C++ 小游戏程序 (共七款) C++编程小游戏_闪耀的天狼星的博客-优快云博客_游戏c++C++跑酷小游戏_闪耀的天狼星的博客-优快云博客。好玩的c++编程小游戏,共六款。代码】C++跑酷小游戏。 阅读详情

相关推荐

【项目立项管理、项目整合管理】30天通过软考高项-第二天

①项目或阶段的概述;②范围目标、范围的评估标准,证明达到完⼯标准的证据;③质量目标、项目和产品质量的评估标准、相关核实信息和实际里程碑交付日期以及偏差原因;④成本目标,包括可接受的成本区间、实际成本,产⽣任何偏差的原因等;⑤最终产品、服务或成果的确认信息的总结;⑥进度计划目标,包括成果是否实现项目预期效益:如果在项目结束时未能实现效益,则指出效益实现程度并预计未来实现情况;

weixin_42520723的博客 1002

Treats for the Cows 区间DP POJ 3186

题目来源:http://poj.org/problem?id=3186 (http://www.fjutacm.com/Problem.jsp?pid=1389) /**  题目意思: 约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱. 为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食. ...

211

【DDSCAT——离散偶极近似仿真程序05】模型设计Matlab代码:多核壳球 、多核壳圆柱

简洁明了,后面及部分给出的都是模型设计的Matlab代码,这些代码都来自于一篇文章:Chin C W S. Localized Surface Plasmon Resonance with the use of Silver and Titanium Oxide Nanostructures[J]. 2011. 一、设计多个核壳球形结构 1)Matlab代码 ...

XD_Yangf的博客 4261

POJ 3186 Treats for the Cows 区间dp

http://poj.org/problem?id=3186 类似的区间dp:https://blog.youkuaiyun.com/qq_32259423/article/details/89221957 题意: 给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次取完。假设你第i次取的数字是x,你可以获得i*x的价值。你需要规划...

swqeaaa的博客 178

值得苦练的100道Python经典练手题(全网最全,附详细答案,建议收藏)

这100道Python练习题涵盖了从基础语法到高级算法、从数据库操作到Web开发的各个方面,是备考数据库系统工程师的绝佳素材。建议按照章节顺序逐一练习,遇到难点可反复钻研,真正掌握每一道题背后的知识点。通过这些练习,不仅能提升Python编程能力,还能加深对数据库系统原理的理解,为考试和实际工作打下坚实基础。

yue_yun_的博客 9396

DSSAT模型实战:从基础配置到气候情景模拟

本文详细介绍了DSSAT模型在农业模拟中的应用,从基础配置到气候情景模拟的全流程实战指南。通过土壤-植物-大气连续体的动态关系建模,DSSAT能精准预测作物产量,误差率低至8%。文章涵盖气象数据处理、土壤参数配置、管理措施调控等核心技巧,并提供了Python脚本和可视化方法,助力农业科研与决策。

weixin_29264201的博客 1016

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

Android SDK安装教程(超详细),从零基础入门到精通,从这篇开始_android sdk下载安装

Android SDK安装教程(超详细),从零基础入门到精通,从这篇开始_android sdk下载安装

Jinmindong 5017

POJ3186-Treats for the Cows【区间dp】

给你n个数字v(1),v(2),...,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次取完。假设你第i次取的数字是x,你可以获得i*x的价值。你需要规划取数顺序,使获得的总价值之和最大。 Input 第一行一个数字n(1&lt;=n&lt;=2000)。 下面n行每行一个数字v(i)。(1&lt;=v(i)&lt;=1000) Output 输出一个数字...

独钓门前月 371

C++(Qt)软件调试---Windows下Qt使用dump定位崩溃位置(1)

在C++/Qt程序崩溃时,往往很难找到崩溃的原因,如果是稳定复现的问题还好,但是多数情况遇见的问题是随机出现的,这时想要快速找到问题并解决就需要通过dump文件定位崩溃位置。

mahuifa的博客 1万+

【INMP441】 MEMS麦克风,让硬件“听得见”,更要“听得清”

INMP441是一款数字MEMS麦克风,采用PDM接口输出高质量数字音频信号。相比传统模拟麦克风,它具有高度集成、抗干扰强、功耗低等优势,支持通过时钟启停实现软件控制开关。该麦克风体积小巧但功能强大,内置MEMS传感器、ADC转换器等模块,适合智能音箱、语音遥控等应用。工程师可通过ESP32等主控芯片轻松连接INMP441,利用多麦克风阵列实现波束成形等高级功能。INMP441展现了数字音频采集的先进技术,为创客和智能硬件开发者提供了优秀的音频解决方案。

深耕CV 1536

POJ 3186 Treats+for+the+Cows 简单dp或者区间dp

题目链接:POJ - 3186 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 recei...

weixin_43824564的博客 194

pip install mysql出现error: subprocess - exited-with-error的解决方案

本文主要介绍了pip install mysql出现error: subprocess - exited-with-error的解决方案,希望能对使用mysql的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 5万+

POJ3186 Treats for the Cows (区间DP)

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

Irimsky 238

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 3186 Treats for the Cows 区间dp

题目中要求我们从中间往两边选,我们可以换一种思考方式,改为从中间往两边选,比如第a次我们选择了第b个,那我们的收入就增加了(n - len) * value[b],len为已经选取的区间长度。 我们用dp[i][j]表示选取i~j区间获得的最大价值,它可以由dp[i+1][j]或者dp[i][j-1]转化而来(就是最后一个选i还是选j),转移方程如下 dp[i][j] = max(dp[i+1][...

qq_19275839的博客 169

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ3186:Treats for the Cows 区间DP

题目链接:http://poj.org/problem?id=3186 一:题意: 给定一个序列,序列中有N个元素,我们每次都可以从序列最前面或者最后面取出一个数, 假设按照上面的方法取完所有原序列的数,形成新的序列为a1,a2,,,an,我们为这个 序列定义一个权值:W=a1 * 1 + a2 * 2 + ,,,,,+an*n。题目要求,求出最大的权值。 二,解析: dp[i][j]

漩涡梦幻 537

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

POJ3186 Treats for the Cows【简单区间DP】

点这里 题意: 给你n个数字v(1),v(2),…,v(n-1),v(n),每次你可以取出最左端的数字或者取出最右端的数字,一共取n次取完。假设你第i次取的数字是x,你可以获得i*x的价值。你需要规划取数顺序,使获得的总价值之和最大。 题解: 我尝试着问自己为什么想到用区间DP——如果只有一个数,那么总价值就是它本身;如果有两个数,那么就要考虑先去其中哪一个;如果有三个数或者更多,都要逐一考虑应该取谁。首先肯定是贪心不了的,很容易能想到一个反驳贪心的样例。但是区间DP,似乎是最对口的解决办法...

lllllan 184

POJ3186 Treats for the Cows 区间DP

POJ3186 Treats for the Cows 区间DP

htrdchh的博客 129

POJ 3186 Treats for the Cows (区间DP)

Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5094   Accepted: 2654 Description FJ has purchased N (1 The treats are interesting fo

jncsw的博客 443

POJ 3186 Treats for the Cows 【区间DP】

Treats for the CowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7379 Accepted: 3911DescriptionFJ has purchased N (1 &lt;= N &lt;= 2000) yummy treats for the cows who get money for giving ...

Emiya丶的博客 192

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

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

tomjobs的博客 408

POJ 3186 Treats for the Cows 详解 (简单区间DP)

Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5516   Accepted: 2877 Description FJ has purchased N (1 The treats are interesting

K键盘里的青春K 855

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

[POJ 3186 | 区间DP]Treats for the Cows

dp[i][j]表示区间 i~区间 j 的最大value,区间长度为j - i + 1,转移方程即为: dp[i][j] = max(dp[i + 1][j] + v[i] * (n - i - j),dp[i][j - 1] + v[j] * (n - i - j)) 先更新短区间,则更新长区间时短区间已经被更新完毕,故dp[1][n]即为最终答案。 #include<iostream> #include<vector> #define debug(x) cout<<#

我们仍未知道那天所看见的花的名字。 134

【区间DP】POJ_3186_Treats for the Cows

Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6369   Accepted: 3341 Description FJ has purchased N (1 The treats are interesting fo

yiluuuuu的博客 266

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

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

165
上一篇: poj 2442 Sequence(贪心,堆)
下一篇: Edit Distance(dp)
cillyb
博客等级 码龄11年 225粉丝 497原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值