CF1155D Beautiful Array 贪心,dp】的更多相关文章

CF115DBeautiful Array 题目大意:给一个有n个元素的a数组,可以选择其中一个区间的所有数都乘上x,也可以不选,求最大子序列和. 如果没有前面的操作,就是只求最大子序列和,我们都知道就一个贪心的思路,当目前序列的和<0了,我们就当它为0,因为它对后面的序列只有负的贡献,完全不会使和增大,只会使和减少.所以我们从左往右,和从右往左,分别处理出没有乘x的最大子序列和maxl和maxr,这样的话,如果我们在区间[l,r]内乘x,那么相应的答案就是(sum[r]-sum[l-1])*x…
I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 We call an array "beautiful array of level L", when all its adjacent number pairs have common factor greater than or equal to L. Obviously, a &qu…
D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and th…
题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: x正数的时候我们就是求出最大字段和然后乘以x即可 x为负数时,我们可以把一段负数乘以x,然后再与之前的正数连接,求出最大字段和,我们想一下 首先并不是直接求出最小字段和就可以的,给出一组样例 10 -1 0 -10 -10 -10 40 -10 -10 20 0 0 答案应该是80,而像上面的做法是…
做法 \(f_{i,0}\)表示以\(i\)结尾未操作时的最大值 \(f_{i,1}\)表示以\(i\)结尾正在操作时的最大值 \(f_{i,2}\)表示以\(i\)结尾已结束操作时的最大值 Code #include<bits/stdc++.h> typedef long long LL; const int maxn=1e6+9; LL ans,n,x; LL a[maxn],f[maxn][3]; int main(){ std::cin>>n>>x; for(L…
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array i…
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. Beauty of array is the maximum sum of some consecutive subarray of t…
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 686  Solved: 357[Submit][Status][Discuss] Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚到肩膀的高度Ai,并且他的胳膊长度为Bi.陷阱深度为H.如果我…
BZOJ_3174_[Tjoi2013]拯救小矮人_贪心+DP Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚到肩膀的高度Ai,并且他的胳膊长度为Bi.陷阱深度为H.如果我 们利用矮人1,矮人2,矮人3,...矮人k搭一个梯子,满足A1+A2+A3+....+Ak+Bk>=H,那么矮人k就可以离开陷阱逃跑了,一 旦一个矮人逃跑了,…
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such that: For every i < j, there is no k with i < k < j such that A[k] * 2 = A[i] + A[j]. Given N, return any beautiful array A.  (It is guaranteed th…