题目大意:现在有一个数列,还有一个数字x,你可以将这个数列中的一段连续子序列同时乘以这个数字x(当然也可以不乘),然后问你最大子段和是多少

做法:dp,你懂的

#include<iostream>
#include<cstdio>
using namespace std;
long long dp[],x,ans;
int n;
int main(){
scanf("%d",&n);
cin>>x;
long long a;
for(int i=;i<=n;i++){
cin>>a;
dp[]=max(0LL,dp[]+a);
dp[]=max(dp[],dp[]+x*a);
dp[]=max(dp[],dp[]+a);
ans=max(ans,dp[]);
}
cout<<ans<<endl;
return ;
}

CF-1155 D.Beautiful Array的更多相关文章

  1. Codeforces 1155 D Beautiful Array DP,最大子段和

    题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...

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

  3. 漂亮数组 Beautiful Array

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

  4. LeetCode - Beautiful Array

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

  5. Educational Codeforces Round 63 D. Beautiful Array

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

  6. 932. Beautiful Array

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

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

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

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

  9. 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 ...

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

随机推荐

  1. python3的ExecJS安装使用

    参考官方文档安装 pip3 install PyExecJS 代码编写 import execjs ctx = execjs.compile(""" function a ...

  2. subprocess模块(了解)

    目录 一.subprocess模块 一.subprocess模块 subprocess模块允许你去创建一个新的进程让其执行另外的程序,并与它进行通信,获取标准的输入.标准输出.标准错误以及返回码等.更 ...

  3. 【swoole】结合swoole 和 nsq 的实际应用

    集合 swoole 的框架设计 为了减少理解度,我尽量的从源头开始引入 1. nsq 案例中是使用 swoole 结合一个php 框架实现的是 NSQ 订阅功能. 启动命令: sudo bash /w ...

  4. spring的事件

    理论 异步的实现方式可以使用事件,或者异步执行: spring中自带了事件的支持,核心是ApplicationEventPublisher; 事件包括三个要点: 事件的定义: 事件监听的定义: 发布事 ...

  5. TCP协议 - 面向连接

    一.TCP特性概览 1.面向连接 TCP是基于连接进行数据交互,通信双方在进行数据交互之前需要建立连接,该连接也只能用在双方之间进行交互.这点不像UDP中的组播和广播,可以在同一组中多个主机交互数据. ...

  6. .net core 的 aop 实现方法汇总

    decorator 不借助第三方DI容器,通过装饰模式通过内置的DI容器实现 https://medium.com/@willie.tetlow/net-core-dependency-injecti ...

  7. requests库的使用、安装及方法的简单介绍

    requests库的使用.安装及方法的简单介绍 1.requests库的概述 requests库是一个简洁且简单的处理HTTP请求的第三方库,是公认的最好获得第三方信息的库. requests库更多信 ...

  8. UserControl关闭

    直接 Application.Current.Shutdown();关闭程序.

  9. 【微信小程序】e.currentTarget和e.target

    什么是事件 事件是视图层到逻辑层的通讯方式. 事件可以将用户的行为反馈到逻辑层进行处理. 事件可以绑定在组件上,当达到触发事件,就会执行逻辑层中对应的事件处理函数. 事件对象可以携带额外信息,如 id ...

  10. haproxy动静分离的验证

    线上出现过项目的静态文件被拦截,不能直接访问.所以想到了haproxy指向对应的url来访问静态文件,想到这里在网络搜索了下,确实有此功能.立即上测试环境验证下: 在listen中增加两行: ​ #定 ...