首页 > 其他分享 >Codeforces 1155D Beautiful Array

Codeforces 1155D Beautiful Array

时间:2023-02-03 12:33:59浏览次数:43  
标签:Beautiful int max ll Codeforces ans Array include dp


Codeforces 1155D  Beautiful Array_ios

Codeforces 1155D  Beautiful Array_#include_02

给你n个数字的数组 然后还有一个 x,你可以选择一段区间乘上 x,输出最大子段和。用一个二维dp来做就行了

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<math.h>
using namespace std;
typedef long long ll;
typedef double ld;
const int INF = 0x3f3f3f3f;
const int N = 300005;
int i,j,k;
int cnt,temp,pos;
int n,m;
ll x;
ll dp[N][3],a[N];

int main()
{
scanf("%d%lld",&n,&x);
for(i=1; i<=n; ++i)
scanf("%lld",&a[i]);
ll ans=0;
for(i=1; i<=n; ++i)
{
dp[i][0]=max(dp[i-1][0]+1ll*a[i],a[i]);//最大子段和
dp[i][1]=max(max(dp[i-1][1],dp[i-1][0])+1ll*a[i]*x,1ll*x*a[i]);//当前数乘x
dp[i][2]=max(max(dp[i-1][2],dp[i-1][1])+a[i],a[i]);//当前数不乘x
ans=max(ans,dp[i][0]);
ans=max(ans,dp[i][1]);
ans=max(ans,dp[i][2]);
}
printf("%lld\n",ans);
return 0;
}

 

 

标签:Beautiful,int,max,ll,Codeforces,ans,Array,include,dp
From: https://blog.51cto.com/u_15952369/6035770

相关文章

  • codeforces 1257E The Contest(lis)
    题意:3堆数,要求使得第一堆的数为前缀,第三堆数为后缀,第二堆数为剩下的数,要求最少调整多少个数的位置使得要求成立。其实就是就把a1,a2,a3排个序然后拼成一个数组,问题转为一个......
  • codeforces 1257C Dominated Subarray
    题意就是找到一个最小的子区间使得这个区间中只有一个数的个数为2.AC代码:#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#inclu......
  • Codeforces1151B-Dima and a Bad XOR(构造)
    这道题真的想复杂了,作为div2的B题肯定不算难。只要构造出任意一种异或和大于1就行,如果第一列的值异或和>1,就直接全输入1即可,如果等于0,我们只要在任意一行中找到一个不等于......
  • Codeforces Round #661 (Div. 3)
    A.RemoveSmallest题意:给定一个序列,每次操作可以任选两个差的绝对值小于等于排序后计算相邻数的差,只要有大于AC代码:constintN=2e5+50;intn,m;inta[N];intmain......
  • Codeforces Round #662 (Div. 2)
    A.RainbowDash,FluttershyandChessColoring题意:有手动写几个找找规律。AC代码:intn,m;intmain(){intT;sd(T);while(T--){sd(n);pd(n/2+1);......
  • Codeforces Round #658 (Div. 2)
    ACommonSubsequence只要找到有一个相同的元素输出即可。AC代码:constintN=1010;inta[N],b[N];intans;intcnt[N];intmain(){intt;sd(t);while(t--){......
  • Codeforces Round #657 (Div. 2)
    A.AcaciusandString题意:给你一个串,你可以把换成任意字符,使得这个串最后只出现一次暴力枚举AC代码:strings;intn;stringT="abacaba";boolcheck(string&a){int......
  • Codeforces Round #656 (Div. 3)
    A.ThreePairwiseMaximums题意:给你三个正整数和,请你找到正整数和,使得,或者确定不可能找到这样的和AC代码:intmain(){intt;sd(t);while(t--){int......
  • Codeforces Round #655 (Div. 2)
    AOmkarandCompletion只要找两个相加不等的数交叉构造即可。AC代码:intmain(){intt;sd(t);while(t--){sd(n);rep(i,1,n){if(i&1)......
  • Codeforces 1360 D. Buying Shovels
    题意:要买个铲子,商店中有中不同的卖法,依次每一次卖到个铲子,现在只能选择其中的一种买法,问最少买几次同一种的买法,使得刚好买到直接选择小于的AC代码:intn,m,k;......