https://www.luogu.org/problemnew/show/P2858

方程很好想,关键我多枚举了一次(不过也没多大关系)

#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(register int i = (l);i <= (r); i++)
using namespace std;
const int N = ;
int n,a[N],f[N][N];
int read
{
int x = ;char ch = getchar();
while(ch < || ch > ) ch = getchar();
while(ch >= && ch <= ) {x = * x + ch - ; ch = getchar();}
return x;
}
//int mymax(int a,int b,int c){int x = max(a,b);int y = max(b,c); return max(x,y);}
int main()
{
n = read; up(i,,n) a[i] = read;
up(i,,n) f[i][i] = a[i];
up(L,,n)//枚举区间长度;
up(i,, (n-L+) ) //枚举左端点;
{
int j = i + L - ; int T = n + - L;
f[i][j] = max(f[i + ][j] + a[i] * T,f[i][j - ] + a[j] * T);//mymax(f[i][j],f[i + 1][j] + a[i] * T,f[i][j - 1] + a[j] * T);
}
printf("%d",f[][n]);
return ;
}

一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows的更多相关文章

  1. Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925

    题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...

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

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

  4. 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows 题解

    P2858 [USACO06FEB]奶牛零食Treats for the Cows 题目描述 FJ has purchased N (1 <= N <= 2000) yummy treat ...

  5. 洛谷 P2858 [USACO06FEB]奶牛零食Treats for the Cows

    题目描述 FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving va ...

  6. AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858

    [USACO06FEB]奶牛零食Treats for the Cows 思路: 区间DP: 代码: #include <bits/stdc++.h> using namespace std ...

  7. 区间DP【p2858】[USACO06FEB]奶牛零食Treats for the Cows

    Description 约翰经常给产奶量高的奶牛发特殊津贴,于是很快奶牛们拥有了大笔不知该怎么花的钱.为此,约翰购置了N(1≤N≤2000)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望 ...

  8. Luogu2858[USACO06FEB]奶牛零食Treats for the Cows (区间DP)

    我是个傻逼,这么水的题都会T #include <iostream> #include <cstdio> #include <cstring> #include & ...

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

随机推荐

  1. JAVA高精度模板

    刚开始还坚持用C++写高精来着,后来发现JAVA写高精方便太多了,所以也来学习一下JAVA高精度的模板. 参考:https://www.cnblogs.com/imzscilovecode/p/883 ...

  2. CentOS Netstat命令

    语法 netstat(选项) 选项 -a或--all:显示所有连线中的Socket: -A<网络类型>或--<网络类型>:列出该网络类型连线中的相关地址: -c或--conti ...

  3. tf.trainable_variables()

    https://blog.csdn.net/shwan_ma/article/details/78879620 一般来说,打印tensorflow变量的函数有两个:tf.trainable_varia ...

  4. 连接SQL常见问题

    HTTP Status 500 – Internal Server Error Type Exception Report Message Request processing failed; nes ...

  5. 什么是PCM?它和.wav文件是什么关系?

    PCM(Pulse Code Modulation----脉码调制录音).所谓PCM录音就是将声音等模拟信号变成符号化的脉冲列,再予以记录.PCM信号是由[1].[0]等符号构成的数字信号,而未经过任 ...

  6. 我的tensorflow学习1

    1.神经元被分成了多层,层与层之间的神经元有连接,而层内之间的神经元没有连接.最左边的层叫做输入层,这层负责接收输入数据:最右边的层叫输出层,我们可以从这层获取神经网络输出数据.输入层和输出层之间的层 ...

  7. iOS 10 之后权限设置

    iOS 10 之后权限设置 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风? 相机权限: Privacy - Camera U ...

  8. Java07-java语法基础(六)面向对象

    Java07-java语法基础(六)面向对象 一.格式化输出 System.out.printf(“%格式字符”,输出项); 1.格式字符: d --->int.byte.short ld -- ...

  9. 先安装win7时IIS的安装

    打开“控制面板”->选择“程序”->选择“打开或关闭windows功能”->在“Internet信息服务”中勾选以下勾选框

  10. mysql数据库存储经度纬度

    使用float或者double会自动四舍五入,用decimal(20,17)当然你用varchar也是可以的