P2858 [USACO06FEB]奶牛零食Treats for the Cows
2024-08-24 15:08:03
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-1]+a[i+l]*(m-l));
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.19
using namespace std;
int n,m;
int a[];
int f[][];
int Max;
int ans;
void in(int &x)
{
int y=;
char c=g();x=;
while(c<''||c>'')
{
if(c=='-')
y=-;
c=g();
}
while(c<=''&&c>='')x=x*+c-'',c=g();
x*=y;
}
void o(int x)
{
if(x<)
{
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main()
{
in(m);
For(jj,,m)
in(a[jj]);
For(i,,m)
f[i][i]=m*a[i];
For(l,,m-)
For(i,,m-l)
f[i][i+l]=max(f[i+][i+l]+a[i]*(m-l),f[i][i+l-]+a[i+l]*(m-l));
o(f[][m]);
return ;
}
最新文章
- bug描述技巧
- Play Framework 完整实现一个APP(十二)
- FPGA与simulink联合实时环路系列——实验一 测试
- centos7 开启防火墙端口 firewalld
- FL2440驱动添加(4)LED 驱动添加
- [ASP.NET MVC] ASP.NET Identity学习笔记 - 原始码下载、ID型别差异
- Jdev Run Page 没有反应
- gotoTop返回顶部 JS
- 代码实现native2assci
- jsoup 对网页中图片解析
- hdu 5012 Dice
- 【jQuery】使用JQ要准备的主要淡入淡出效果
- 在使用cognos时遇到的问题记录帖
- b树和hash树的应用场景
- 【mongo】查询超时处理
- Spark配置参数详解
- django中forms和modelform组件的区别
- RuntimeError: Model class apps.users.models.User doesn&#39;t declare an explicit app_label and isn&#39;t in an application in INSTALLED_APPS.
- weblogic优化(内存、线程数和启动速度)
- Nginx详解十三:Nginx场景实践篇之防盗链