AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858
[USACO06FEB]奶牛零食Treats for the Cows
思路:
区间DP;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 2005
#define ll long long
ll n,ai[maxn],dp[maxn][maxn],sum[maxn];
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
int main()
{
in(n);
for(ll i=;i<=n;i++) in(ai[i]),sum[i]=sum[i-]+ai[i],dp[i][i]=ai[i];
for(ll i=;i<=n;i++)
{
for(ll v=;v+i<=n;v++)
{
ll l=v,r=v+i;
dp[l][r]=max(dp[l+][r],dp[l][r-])+sum[r]-sum[l-];
}
}
cout<<dp[][n];
return ;
}
AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858的更多相关文章
- 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- ...
- 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 ...
- 洛谷 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【p2858】[USACO06FEB]奶牛零食Treats for the Cows
Description 约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱.为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望 ...
- Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925
题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...
- 洛谷P2858 【[USACO06FEB]奶牛零食Treats for the Cows】
我们可以记录头和尾再加一个卖了的零食数目,如果头超过尾就return 0. 如果遇到需要重复使用的数,(也就是不为零的d数组)就直接return d[tuo][wei]. 如果没有,就取卖头一个与最后 ...
- 一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows
https://www.luogu.org/problemnew/show/P2858 方程很好想,关键我多枚举了一次(不过也没多大关系) #include <bits/stdc++.h> ...
- [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[ ...
随机推荐
- ACM1558两线段相交判断和并查集
Segment set Problem Description A segment and all segments which are connected with it compose a seg ...
- Leetcode 295. 数据流的中位数
1.题目要求 中位数是有序列表中间的数.如果列表长度是偶数,中位数则是中间两个数的平均值. 例如, [2,3,4] 的中位数是 3 [2,3] 的中位数是 (2 + 3) / 2 = 2.5 设计一个 ...
- A星寻路算法-Mind&Hand(C++)
//注1:Mind & Hand,MIT校训,这里指的理解与实现(动脑也动手) //注2:博文分为两部分:(1)理解部分,为参考其他优秀博文的摘要梳理:(2)代码部分,是C++代码实现的,源码 ...
- c# 折半查找法实现代码
] { , , , , , , , , , , , , , , , , , , , }; , i; string j, k; , ); ) { k = String.Format("未找到{ ...
- Tomcat设置开启时自动访问某个servlet类存在的问题
<servlet> <servlet-name>****</servlet-name> <servlet-class>****</servlet- ...
- JS日期对象扩展-日期格式化
日期对象扩展(日期格式化)yyyy-MM-dd hh:mm:ss.S Date.prototype.format = function(fmt) { var o = { "M+" ...
- jquery禁用按钮
$('#sub').click(function () { var self = $(this); ,'#01b637') ){ return false; } }); function onesho ...
- Installing JDK7 on Ubuntu
1. # sudo add-apt-repository ppa:webupd8team/java 2. # sudo apt-get update 3. # sudo apt-get insta ...
- Sass 基本特性-运算 感觉满满都是坑
Sass中的基本运算 一.加法 在 CSS 中能做运算的,到目前为止仅有 calc() 函数可行.但在 Sass 中,运算只是其基本特性之一. sass做加法运算是可以不考虑参数带单位,但需 ...
- loj515 「LibreOJ β Round #2」贪心只能过样例
传送门:https://loj.ac/problem/515 [题解] 容易发现S最大到1000000. 于是我们有一个$O(n^2*S)$的dp做法. 容易发现可以被bitset优化. 于是复杂度就 ...