一道区间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[ ...
 
随机推荐
- pta6-17(另类堆栈)
			
题目链接:https://pintia.cn/problem-sets/1101307589335527424/problems/1101313244872126464 题意:一种新的堆栈,用Top表 ...
 - 160. Intersection of Two Linked Lists (List;Two-Pointers)
			
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
 - const和volatile分析
			
c语言中const修饰的变量是只读的,不能直接作为赋值号的左值,其本质还是变量:会占用内存空间:本质上const在编译器有用,运行时无用(还是可以通过指针改变它的值) ; int *p=&ab ...
 - RocketMq --consumer自动实现负载均衡
			
这边使用一个producer和两个consumer是实现负载均衡. 看一下代码示例 package com.alibaba.rocketmq.example.message.model; import ...
 - Delphi异步编程:匿名线程与匿名方法
			
异步编程,是项目中非常有用的而且常用的一种方法,大多以线程实现. 而Delphi传统方法使用线程略为烦琐,好在其后续版本中,提供一些方法,简化一些操作. 几个概念: 匿名线程:TAnonymousTh ...
 - python颜色及背景
			
linux终端中的颜色是用转义序列控制的,转义序列是以ESC开头,可以用\033完成相同的工作(ESC的ASCII码用十进制表示就是27,等于用八进制表示的33). 书写格式,和相关说明如下: 1 2 ...
 - undefined reference to...
			
wj@wj-Inspiron-:~/Downloads/LBD_Descriptor/build$ cmake .. -- Configuring done -- Generating done -- ...
 - JS中判断某个字符串是否包含另一个字符串的五种方法
			
String对象的方法 方法一: indexOf() (推荐) ? 1 2 var str = "123" console.log(str.indexOf("2&qu ...
 - mysql 安装后出现 10061错误
			
#服务器端 提示 The vervice already exists! The current server installed #mysqld 服务没有启动 解决办法 移除原来的mysql服务 ...
 - windows2003两台服务器,局域网之间不能互相访问
			
准备在两台服务器之间,映射网络驱动器,但怎么也连不上了. 可以在网络邻居中看到对方的机器,但就是访问不到共享的文件,也无法做网络映射. 搜索了一下,发现在是因为防火墙中,没有把"文件和打印机 ...