一道区间DP的水题 -- luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows
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的更多相关文章
- Luogu P2858 [USACO06FEB]奶牛零食Treats for the Cows 【区间dp】By cellur925
题目传送门 做完A Game以后找道区间dp练练手...结果这题没写出来(哭). 和A Game一样的性质,从两边取,但是竟然还有天数,鉴于之前做dp经常在状态中少保存一些东西,所以这次精心设计了状态 ...
- 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 ...
- 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)份美味的零食来卖给奶牛们.每天约翰售出一份零食.当然约翰希望 ...
- Luogu2858[USACO06FEB]奶牛零食Treats for the Cows (区间DP)
我是个傻逼,这么水的题都会T #include <iostream> #include <cstdio> #include <cstring> #include & ...
- [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[ ...
随机推荐
- NumPy 字符串函数
NumPy 字符串函数 以下函数用于对 dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量化字符串操作. 它们基于 Python 内置库中的标准字符串函数. ...
- 图片Bitmap在本地的存储与读取 File
将Bitmap存储到本地: public void SaveImage(Bitmap image, String user_id){ //照片通常存在DCIM文件夹中 String sdCardDir ...
- 颜色 color
在res/values文件夹下的color.xml添加 <?xml version="1.0" encoding="utf-8"?> <res ...
- 了解Queue
在并发队列上JDK提供了两套实现,一个是以ConcurrentLinkedQueue为代表的高性能队列,一个是以BlockingQueue接口为代表的阻塞队列,无论哪种都继承自Queue, 可以对应着 ...
- Delphi中记录体做为属性的赋值方法
1. 起源 此问题源于[秋风人事档案管理系统]用Delphi XE重编译中所发现. 快十年了,当初Delphi 7所编写项目,想用Delphi XE重新编译,并打算做为Free软件发布,编译错误中发现 ...
- 联想G510安装win7系统
1.插入系统盘重启(要按Fn+f12) 2默认下一步 3.选择自定义 4.选择需要将系统安装到的分区,格式化,然后下一步 5.默认下一步 安装到这里就成功了 6.问题处理: 第4步时出现 Window ...
- 【 python】输出随机的字符或数字
随机输出0-9的数字 from random import choice x = choice([0,1,2,3,4,5,6,7,8,9]) print x 输出结果 #python first.py ...
- 有关https有的网站可以访问有的访问不了的问题
在开发中遇到这种情况,在开发工具里面访问可以,当时到了手机上之后就发现有的请求可以正常获取数据,有的则不行. 都是使用https地址,也配置后台了,但是就是不出数据,总是无法请求服务. 后来检查在手机 ...
- linux arm-linux-gcc 安装编译
1,将 .tgz 安装包通过SSH传至ubuntu 2,tar -zxvf arm-linux-gcc.tgz 解压 3,配置环境变量(由于鄙人只需其中一个用户使用,所以直接再其主目录) ...
- Java运算符号,对象赋值,别名
生活发生的一切,才会促使着我继续前行,今天继续更新哦,看书中的代码练习. 例子1 引入net.mindview.util.Print.* ,方便打印结果. package com.date0529; ...