D. Beautiful Array
题目: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的更多相关文章
- [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 ...
- 漂亮数组 Beautiful Array
2019-04-06 16:09:56 问题描述: 问题求解: 本题还是挺有难度的,主要是要考虑好如何去进行构造. 首先考虑到2 * A[i] = A[j] + A[k],那么j,k就必须是同奇同偶, ...
- LeetCode - Beautiful Array
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- Educational Codeforces Round 63 D. Beautiful Array
D. Beautiful Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 932. Beautiful Array
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...
- 北邮校赛 I. Beautiful Array(DP)
I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...
- [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 ...
- 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 ...
- [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 ...
- Codeforce 1155D Beautiful Array(DP)
D. Beautiful Array You are given an array aa consisting of nn integers. Beauty of array is the maxim ...
随机推荐
- linux dd、echo 、watch、fuser命令
一.dd命令 以数据流进行复制,cp命令则是以文件为单位进行复制 if=数据来源 of=数据存储目标 bs=# 复制的字节数 count=# 复制几个bs seek=# 跳过多 ...
- js混合计算字符串字节长度
js混合计算字符串字节长度 function getBt(str) { ) { var char = str.match(/[^\x00-\xff]/ig); : char.length); } el ...
- Cocos2d-x中屏幕截取
类似半屏幕文字向上滚动,到一定位置,逐渐消失 这里用到了CCLayer的visit()方法 首先新建一个类TxtLayer 继承CCLayer class TxtLayer : public coc ...
- Educational Codeforces Round 30D. Merge Sort
归并排序的逆操作,每次二分时把第二段第一位与第一段最后一位开始往前第一个比它大的数交换位置 可以用归并排序验证答案对不对 #include<bits/stdc++.h> #define f ...
- 命令行执行大sql文件
mysql -h localhost -u root -p 123456 < F:/hello world/niuzi.sql
- Java_基础_01_static和final
二.参考资料 1.java入门之关键字static和final 2.static和final的区别
- 关于c++中的全局变量(不赋值的全局变量算定义)
定义有三种: 1.不赋值的定义:int a; 2.赋值的定义:int a=5; 或者 int a;a=5; 3.加extern的定义:extern int a=5;//其实和不加是一样的. 声明只有一 ...
- leetcode 34 Search for a Range(二分法)
Search for a Range Given a sorted array of integers, find the starting and ending position of a give ...
- Angular Chart 使用说明(基于angular工程)
Angular Chart是基于Chart.js的angular组件,引入项目后直接操作数据即可. 引用方法: 分别将Chart.js.angular-chart.js.angular-char ...
- Log Structured Merge Trees(LSM) 原理
http://www.open-open.com/lib/view/open1424916275249.html