我是个傻逼,这么水的题都会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)的更多相关文章

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

  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. AC日记——[USACO06FEB]奶牛零食Treats for the Cows 洛谷 P2858

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

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

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

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

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

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

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

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

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

  9. 洛谷P2858 【[USACO06FEB]奶牛零食Treats for the Cows】

    我们可以记录头和尾再加一个卖了的零食数目,如果头超过尾就return 0. 如果遇到需要重复使用的数,(也就是不为零的d数组)就直接return d[tuo][wei]. 如果没有,就取卖头一个与最后 ...

随机推荐

  1. JAVA - 线程从创建到死亡的几种状态都有哪些?

    JAVA - 线程从创建到死亡的几种状态都有哪些? 新建( new ):新创建了一个线程对象. 可运行( runnable ):线程对象创建后,其他线程(比如 main 线程)调用了该对象 的 sta ...

  2. 【SpringSecurity系列1】基于SpringSecurity实现前后端分离无状态Rest API的权限控制

    源码传送门: https://github.com/ningzuoxin/zxning-springsecurity-demos/tree/master/01-springsecurity-state ...

  3. Jmeter基础入门应用举例

    举例当然应该有接口下面以常用的百度搜索接口为例: 1.接口地址: http://www.baidu.com/s?ie=utf-8&wd=jmeter性能测试 2.请求参数 ie:编码方式,默认 ...

  4. C#和Java,究竟选哪个方向?我只说事实,你自己分析……

    好久没到园子里面逛了,回来看了看,.NET有点式微呀?Java/Spring/Linux--比以前多了很多,为什么?博客园可是.NET的大本营了呀! 好吧,我承认,飞哥也动摇了,去年在ASP.NET的 ...

  5. jdk8对象集合转map集合

    package koukay.Controller.Controllers; import koukay.Portal.webservices.Entity.User; import com.fast ...

  6. 第五章、Linux网络服务之yum仓库

    目录 一.yum仓库简介 二.yum配置文件 1yum主配置文件 2日志文件 三.yum命令详解 1查询软件包命令 2查询软件包组命令 3yum安装升级 4 软件卸载 四.搭建yum仓库 本地仓库 h ...

  7. UiPath条件判断活动If的介绍和使用

    if的介绍 if语句是指编程语言(包括c语言.C#.Python.Java.汇编语言等)中用来判定所给定的条件是否满足,根据判定的结果(真或假)决定执行给出的两种操作之一. if在UiPath中的使用 ...

  8. 《HelloGitHub》第 75 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  9. (原创)【MAUI】一步一步实现“悬浮操作按钮”(FAB,Floating Action Button)

    一.前言 MAUI,跨平台的 GUI 框架,基本介绍本文不再赘述. 话不多说,既然可以跨平台,那么我们就来实现一个在移动端很常用的控件:悬浮操作按钮(FAB,Floating Action Butto ...

  10. GameFramework食用指南

    1.框架简介 GF框架分两部分,GameFramework(GF)和UnityGameFramework(UGF): 通过接口的形式对Unity引擎进行了解耦: GF独立于Unity,具体业务逻辑实现 ...