题目: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. Storm- Storm作业提交运行流程

    用户编写Storm Topology 使用client提交Topology给Nimbus Nimbus指派Task给Supervisor Supervisor为Task启动Worker Worker执 ...

  2. JS常用工具类代码

    http://www.cnblogs.com/liszt/archive/2011/08/16/2140007.html js/javascript删除字符串中的html标签 function rem ...

  3. 一个基于特征向量的近似网页去重算法——term用SVM人工提取训练,基于term的特征向量,倒排索引查询相似文档,同时利用cos计算相似度

    摘  要  在搜索引擎的检索结果页面中,用户经常会得到内容相似的重复页面,它们中大多是由于网站之间转载造成的.为提高检索效率和用户满意度,提出一种基于特征向量的大规模中文近似网页检测算法DDW(Det ...

  4. js事件绑定的几种方式与on()、bind()的区别

    版权声明:本文为博主原创文章,未经博主允许不得转载 一直不是很理解几种js事件绑定之间的区别与联系,今天百度了一下,在此做一总结: 1.如果只是简单的绑定一个事件,可以直接写在行内,点击执行一个函数, ...

  5. 机器学习 Logistic Regression

    Logistic Regression 之前我们讨论过回归问题,并且讨论了线性回归模型.现在我们来看看分类问题,分类问题与回归问题类似,只不过输出变量一个是离散的,一个是连续的.我们先关注二分类问题, ...

  6. 跨平台的WebRTC客户端框架:OpenWebRTC

    Webrtc的ios框架编译 http://www.th7.cn/Program/IOS/201502/390418.shtml WebRTC in WebKit : http://www.webrt ...

  7. Gym - 100570B :ShortestPath Query(SPFA及其优化)

    题意:给定N点M边的有向图,每条边有距离和颜色,一条有效路径上不能有相邻的边颜色相同.现在给定起点S,多次讯问S到点X的最短有效距离. TLE思路:用二维状态dis(u,c)表示起点到u,最后一条边的 ...

  8. HihoCoder1338 A Game(记忆化搜索)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a game. There is an integ ...

  9. ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)

    Problem Description In Geometry, the problem of track is very interesting. Because in some cases, th ...

  10. 【LeetCode】080. Remove Duplicates from Sorted Array II

    题目: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For ex ...