题目:http://codeforces.com/contest/1155/problem/D

给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和

竟然是很简单的dp!!!

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll zero = ;
ll n,x,k,dp[],cnt;
int main()
{
scanf("%lld%lld",&n,&x);
memset(dp,,sizeof(dp));
for(ll i = ;i <= n;i++)
{
scanf("%lld",&k);
dp[] = max(zero , dp[] + k); // 第一种状态 dp[1] 求最大字段和即可
dp[] = max(dp[] , dp[] + k*x); // 第二种状态 dp[2]应该是前面的最大字段和+当前的数
dp[] = max(dp[] , dp[] + k); // 第三种状态 dp[3]显然是前面两段的和再加上当前
cnt = max(cnt , dp[]);
}
printf("%lld",cnt);
return ;
}

D. Beautiful Array的更多相关文章

  1. [Swift]LeetCode932. 漂亮数组 | Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  2. 漂亮数组 Beautiful Array

    2019-04-06 16:09:56 问题描述: 问题求解: 本题还是挺有难度的,主要是要考虑好如何去进行构造. 首先考虑到2 * A[i] = A[j] + A[k],那么j,k就必须是同奇同偶, ...

  3. LeetCode - Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  4. Educational Codeforces Round 63 D. Beautiful Array

    D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. 932. Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  6. 北邮校赛 I. Beautiful Array(DP)

    I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  7. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  8. LC 932. Beautiful Array

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  9. [LeetCode] 932. Beautiful Array 漂亮数组

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...

  10. Codeforce 1155D Beautiful Array(DP)

    D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maxim ...

随机推荐

  1. Linux课程---4、Linux目录结构及常用命令(目录结构)

    Linux课程---4.Linux目录结构及常用命令(目录结构) 一.总结 一句话总结: 家目录:./root:root用户的家目录 能执行的程序:./bin:所有用户都能执行的程序:./sbin:只 ...

  2. 分享知识-快乐自己:运行(wordcount)案例

    运行 wordcount 案例: 一):大数据(hadoop)初始化环境搭建 二):大数据(hadoop)环境搭建 三):运行wordcount案例 四):揭秘HDFS 五):揭秘MapReduce ...

  3. 【BZOJ 4709】柠檬 斜率优化dp+单调栈

    题意 给$n$个贝壳,可以将贝壳分成若干段,每段选取一个贝壳$s_i$,这一段$s_i$的数目为$num$,可以得到$num^2\times s_i$个柠檬,求最多能得到几个柠檬 可以发现只有在一段中 ...

  4. 实现stack 加上·getMin功能 时间复杂度为O(n)

    package com.hzins.suanfa; import java.util.Stack; /** * 实现stack 加上·getMin功能 时间复杂度为O(n) * @author Adm ...

  5. OpenCV - Android Studio 中集成Opencv环境(不包含opencv_contrib部分)

    OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉库,支持的运行环境也是非常的多,这篇文章主要讲的是Android环境集成OpenCV(IDE是Android Studio,我想Eclip ...

  6. cmd cvf war包

    1.进入要打包的目录下 --> cmd d: cd \路径 jar -cvf 包名.war * 2.解压 进入需要解压的目录 cd /depa123/webapps/css jar -xvf / ...

  7. 【转】 Pro Android学习笔记(五九):Preferences(3):EditText和Ringtone Preference

    目录(?)[-] EditText Preferences xml文件 设备的存贮文件 Ringtone Preferences EditText Preferences xml文件 在res/xml ...

  8. 【转】 Pro Android学习笔记(四二):Fragment(7):切换效果

    目录(?)[-] 利用setTransition 利用setCustomAnimations 通过ObjectAnimator自定义动态效果 程序代码的编写 利用fragment transactio ...

  9. Java常见设计模式之责任链模式

    原文地址:  http://www.cnblogs.com/java-my-life/archive/2012/05/28/2516865.html 在阎宏博士的<JAVA与模式>一书中开 ...

  10. Windows X64平台搭建Java开发环境

       JDK下载路径:www.oracle.com/technetwork/java/javase/downloads/index.html 下载JDK(Java Develop Kit) (1)针对 ...