Luogu2858[USACO06FEB]奶牛零食Treats for the Cows (区间DP)
我是个傻逼,这么水的题都会T
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long
#define ON_DEBUG
#ifdef ON_DEBUG
#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#endif
struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std;
const int N = 2007;
int f[N][N], a[N];
int main(){
//FileOpen();
int n;
io >> n;
R(i,1,n){
io >> a[i];
f[i][i] = a[i] * n;
}
R(len,2,n){
R(l,1,n){
int r = l + len - 1;
if(r > n) break; // what happend to my mind that I'm dare to write 'continue' !
f[l][r] = Max(f[l][r - 1] + a[r] * (n - len + 1), f[l + 1][r] + a[l] * (n - len + 1)); // Shit, I put another for insideeeeeeeeeeeeeeee
}
}
printf("%d\n", f[1][n]);
return 0;
}
Luogu2858[USACO06FEB]奶牛零食Treats for the Cows (区间DP)的更多相关文章
- [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[ ...
- 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 ...
- AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858
[USACO06FEB]奶牛零食Treats for the Cows 思路: 区间DP: 代码: #include <bits/stdc++.h> using namespace std ...
- 洛谷 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]. 如果没有,就取卖头一个与最后 ...
随机推荐
- SSH 的使用和配置
命令 ssh user@hostname -p port Windows 下首次执行这个命令会由于 Windows 默认没有运行 ssh-agent 导致无法连接,可以通过在 powershell 下 ...
- Docker容器:将带UI的程序直接转为Web应用,so easy
摘要:使用Docker容器,将带UI的程序,直接转换为Web应用.很方便,跟大家分享一下. 本文分享自华为云社区<使用Docker容器,将带UI的程序,直接转为Web应用>,作者:tsjs ...
- np.linspace,numpy中的linspace()
import numpy as np x=np.linspace(1,10) y=np.linspace(1,10,num=10,retstep=True)#num可省略 print(x) print ...
- 【生成对抗网络学习 其一】经典GAN与其存在的问题和相关改进
参考资料: 1.https://github.com/dragen1860/TensorFlow-2.x-Tutorials 2.<Generative Adversarial Net> ...
- C语言 C++1X STL QT免费视频课程 QT5界面开发美化 式样表 QML
C/C++/QT界面开发界面美化视频课程系列 课程1 C语言 C++1X STL QT免费视频课程 QT5界面开发美化 式样表 QML 返回顶部 课程1 C语言 C++1X STL QT免费视 ...
- mariadb安装配置(主从配置)
主服务器192.168.206.183 从服务器192.168.206.193 1.创建并编辑 /etc/yum.repos.d/MariaDB.repo文件(主从都要做) [mariadb] nam ...
- 自建批量更改标准BO数据程序
by zyi
- 洛谷P4017 最大食物链数量 dfs
老规矩,传送门 做题从头到尾的思路: 1. 这个题明显就是dfs数数量了,简单,邻接矩阵干他! TLE警告,8个点 额... 2. 老师说这玩意不能邻接矩阵?没事,还有邻接表,再来! 再次TLE 8个 ...
- C++ delete后的指针在不同编译器下的状态差异
今天看到小伙伴分享的一个问题,小伙伴用的MSVC2019编译器,在对delete后的指针进行取值操作时触发了访问冲突. #include<iostream> using namespace ...
- 在 SQL Server 中使用 Try Catch 处理异常
如何在 SQL Server 中使用 Try Catch 处理错误? 从 SQL Server 2005 开始,我们在TRY 和 CATCH块的帮助下提供了结构错误处理机制.使用TRY-CATCH的语 ...