bzoj1652 / P2858 [USACO06FEB]奶牛零食Treats for the Cows
P2858 [USACO06FEB]奶牛零食Treats for the Cows
区间dp
设$f[l][r]$为取区间$[l,r]$的最优解,蓝后倒着推
$f[l][r]=max(f[l+1][r]+a[l]*p,f[l][r-1]+a[r]*p)$
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int max(int a,int b){return a>b?a:b;}
#define N 2010
int a[N],f[N][N],n;
int main(){
//freopen("P2858.in","r",stdin);
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d",&a[i]),f[i][i]=a[i]*n;
for(int i=;i<=n;++i)
for(int l=,r,p;l+i-<=n;++l){
r=l+i-; p=n-i+;
f[l][r]=max(f[l+][r]+a[l]*p,f[l][r-]+a[r]*p);
}
printf("%d",f[][n]);
return ;
}
bzoj1652 / P2858 [USACO06FEB]奶牛零食Treats for the Cows的更多相关文章
- P2858 [USACO06FEB]奶牛零食Treats for the Cows
P2858 [USACO06FEB]奶牛零食Treats for the Cows区间dp,级像矩阵取数, f[i][i+l]=max(f[i+1][i+l]+a[i]*(m-l),f[i][i+l- ...
- 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows 题解
P2858 [USACO06FEB]奶牛零食Treats for the Cows 题目描述 FJ has purchased N (1 <= N <= 2000) yummy treat ...
- 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows
题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving va ...
- 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows
https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...
- Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925
题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...
- AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858
[USACO06FEB]奶牛零食Treats for the Cows 思路: 区间DP: 代码: #include <bits/stdc++.h> using namespace std ...
- 区间DP【p2858】[USACO06FEB]奶牛零食Treats for the Cows
Description 约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱.为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望 ...
- 洛谷P2858 【[USACO06FEB]奶牛零食Treats for the Cows】
我们可以记录头和尾再加一个卖了的零食数目,如果头超过尾就return 0. 如果遇到需要重复使用的数,(也就是不为零的d数组)就直接return d[tuo][wei]. 如果没有,就取卖头一个与最后 ...
- [luoguP2858] [USACO06FEB]奶牛零食Treats for the Cows(DP)
传送门 f[i][j][k] 表示 左右两段取到 i .... j 时,取 k 次的最优解 可以优化 k 其实等于 n - j + i 则 f[i][j] = max(f[i + 1][j] + a[ ...
随机推荐
- poj3304 Segments【计算几何】
C - Segments POJ - 3304 最近开始刷计算几何了 公式好多完全不会 数学不行 几何不行 记忆力不行 当机 查的题解 就当复习吧 这套专题拿来熟悉一下计算几何模板 #include ...
- pcl学习笔记(二):点云类型
不同的点云类型 前面所说的,pcl::PointCloud包含一个域,它作为点的容器,这个域是PointT类型的,这个域是PointT类型的是pcl::PointCloud类的模板参数,定义了点云的存 ...
- opencv学习笔记霍夫变换——直线检测
参考大佬博文:blog.csdn.net/jia20003/article/details/7724530 lps-683.iteye.com/blog/2254368 openCV里有两个函数(比较 ...
- 一般图的着色 - [Welch Powell法][贪心]
原本这是离散数学的期末作业,因为对图论比较熟悉,就先看了一下图论题: 引用<离散数学(左孝凌版)>(其实就是我们的离散数学课本……): 用韦尔奇·鲍威尔法对图G进行着色,其方法是: a)将 ...
- redis系列之数据库与缓存数据一致性解决方案
redis系列之数据库与缓存数据一致性解决方案 数据库与缓存读写模式策略 写完数据库后是否需要马上更新缓存还是直接删除缓存? (1).如果写数据库的值与更新到缓存值是一样的,不需要经过任何的计算,可以 ...
- POJ_2019_Cornfields
Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7444 Accepted: 3609 Descri ...
- OLTP与OLAP
当今的数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction processing).联机分析处理OLAP(On-Line Analytical Processing ...
- MySQL完全卸载方法
1.在控制面板里把Mysql正常卸载 2.C:\Documents and Settings\All Users\Application Data\MySQL 这里还有MySQL的文件,必须要删除 注 ...
- Atom编辑器折腾记
http://blog.csdn.net/bomess/article/category/3202419/2 Atom编辑器折腾记_(1)介绍下载安装 Atom编辑器折腾记_(2)基础了解使用 Ato ...
- SVN: is scheduled for addition, but is missing
删除文件夹后点commit提交,但是报错,报错内容如下:提示 "svn: Commit failed (details follow): svn: '/***/xxx.c' is sched ...