题目: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. python3字符串属性(二)

    1.S.isdecimal() -> bool    Return True if there are only decimal characters in S, False otherwise ...

  2. php 简单笔记

    1.时间 $date1 = "2014-11-11"; echo date('Y-m-d',strtotime("$date1 +5 day")); //输出结 ...

  3. algorithm 简单用法

    algorithm 简单用法 #include <iostream> #include <vector> #include <algorithm> using na ...

  4. 【Educational Codeforces Round 38】D. Buy a Ticket 堆优化Dijkstra

    题意 给定一张无向图,对每个点$i\in S$求$\min_{j\in S} {2\times d(i,j)+a_j}$ 考虑多源多汇最短路会超时,换个角度考虑每个$j$,如果$j=i$,那么答案为$ ...

  5. 通俗解释glLoadIdentity(),glPushMatrix(),glPopMatrix()的作用

    通俗解释glLoadIdentity(),glPushMatrix(),glPopMatrix()的作用 (2012-04-02 09:17:28) 转载▼   对于glLoadIdentity(), ...

  6. leetcode 205. Isomorphic Strings(哈希表)

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  7. JDBC获得数据库连接及使用

    1.Connection  Java.sql.Driver 接口是所有 JDBC 驱动程序需要实现的接口.这个接口是提供给数据库厂商使用的,不同数据库厂商提供不同的实现 在程序中不需要直接去访问实现了 ...

  8. 本地windows安装memcached服务

    1.安装到系统服务中: 在doc中:执行此软件 memcached.exe -d install(如果提示错误,要找到cmd.exe用管理员身份打开) 安装后在,服务里吗就有个服务了,如果没有启动,点 ...

  9. ACM学习历程—Hihocoder 1290 Demo Day(动态规划)

    http://hihocoder.com/problemset/problem/1290 这题是这次微软笔试的第三题,过的人比第一题少一点,这题一眼看过去就是动态规划,不过转移方程貌似不是很简单,调试 ...

  10. vmware station中 UDEV 无法获取共享存储磁盘的UUID,症状: scsi_id -g -u -d /dev/sdb 无返回结果。

    1.确认在所有RAC节点上已经安装了必要的UDEV包 [root@11gnode1 ~]# rpm -qa|grep udevsystem-config-printer-udev-1.1.16-25. ...