[BOI2007]Sequence 序列问题 BZOJ1345
题目描述
对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和ai+1用一个元素max(ai,ai+1)替代,这样得到一个比原来序列短的新序列。这一操作的代价是max(ai,ai+1)。进行n-1次该操作后,可以得到一个长度为1的序列。
我们的任务是计算代价最小的reduce操作步骤,将给定的序列变成长度为1的序列。
输入输出格式
输入格式:
第一行为一个整数n( 1 <= n <= 1,000,000 ),表示给定序列的长度。
接下来的n行,每行一个整数ai(0 <=ai<= 1, 000, 000, 000),为序列中的元素。
输出格式:
只有一行,为一个整数,即将序列变成一个元素的最小代价。
输入输出样例
说明
提示 30%的测试数据 n<=500; 50%的测试数据 n <= 20,000。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 2000005
#define inf 0x3f3f3f3f
#define INF 9999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ ll qpow(ll a, ll b, ll c) {
ll ans = 1;
a = a % c;
while (b) {
if (b % 2)ans = ans * a%c;
b /= 2; a = a * a%c;
}
return ans;
} int n;
int a[maxn]; int main()
{
//ios::sync_with_stdio(0);
rdint(n);
for (int i = 1; i <= n; i++)rdint(a[i]);
ll sum = 0;
for (int i = 1; i < n; i++) {
sum += max(a[i], a[i + 1]);
}
cout << sum << endl;
return 0;
}
[BOI2007]Sequence 序列问题 BZOJ1345的更多相关文章
- P4393 [BOI2007]Sequence 序列问题[贪心]
题目描述 对于一个给定的序列a1, -, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和ai+1用一个元素max(ai,ai+1)替代,这样得到一个比原来序列短的新序列.这一 ...
- python 数据类型(sequence 序列、dictionary 词典、动态类型)
文章内容摘自:http://www.cnblogs.com/vamei 1.sequence 序列 sequence(序列)是一组有顺序的元素的集合 (严格的说,是对象的集合,但鉴于我们还没有引入“对 ...
- python中的sequence(序列)
摘要 这篇文章主要是为了让自己记住字典不是序列,python中序列的类型 序列化的定义 有个朋友问我,什么是序列化,我瞬间懵了,然后查了一下,发现廖雪峰老师给出了一个很舒服的解释: 序列化:我们把变量 ...
- PostgreSQL之Sequence序列(转)
本文转载自:https://blog.csdn.net/omelon1/article/details/78798961 Sequence序列 Sequence是一种自动增加的数字序列,一般作为行或者 ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- Python sequence (序列)
序列简介 sequence 是一组有序元素的组合 序列可以是多个元素,也可以一个元素都没有 序列有2种:tuple(定值表).List(表) D:\python\Python_Day>pytho ...
- Sql Server增加Sequence序列语句
1.创建序列 下面的示例创建名为 DecSeq 使用一个序列 十进制 具有介于 0 到 255 之间的数据类型.序列以 125 开始,每次生成数字时递增 25. 因为该序列配置为可循环,所以,当值超过 ...
- NOI模拟赛(3.15) sequence(序列)
Description 小A有N个正整数,紧接着,他打算依次在黑板上写下这N个数.对于每一个数,他可以决定将这个数写在当前数列的最左边或最右边.现在他想知道,他写下的数列的可能的最长严格上升子序列(可 ...
- oracle创建sequence序列语法
在oracle中sequence就是序号,每次取的时候它会自动增加.sequence与表没有关系 1.create sequence create sequence SEQ_LOG_ID minval ...
随机推荐
- [转]RabbitMQ三种Exchange模式(fanout,direct,topic)的性能比较
RabbitMQ中,所有生产者提交的消息都由Exchange来接受,然后Exchange按照特定的策略转发到Queue进行存储 RabbitMQ提供了四种Exchange:fanout,direct, ...
- Spring-@value用法详解
为了简化读取properties文件中的配置值,spring支持@value注解的方式来获取,这种方式大大简化了项目配置,提高业务中的灵活性. 一.两种使用方法 1.@Value("#{co ...
- pipeline(管道的连续应用)
# -*- coding: utf-8 -*- """ Created on Tue Aug 09 22:55:06 2016 @author: Administrato ...
- DAY19-Pillow制作验证码
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...
- CentOS6.5 安装ORACLE 安装界面乱码解决方案
在终端运行 export LANG=EN_US 然后再执行安装程序
- CustomProgressDialog
1 ,布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andr ...
- 2018网络预选赛 青岛 H
题目链接:https://pintia.cn/problem-sets/1036903825309761536/problems/1041156323504345088 题意:小明从某一点出发,向右方 ...
- QT5环境搭建
https://blog.csdn.net/liang19890820/article/details/53931813
- PCL—点云分割(最小割算法) 低层次点云处理
1.点云分割的精度 在之前的两个章节里介绍了基于采样一致的点云分割和基于临近搜索的点云分割算法.基于采样一致的点云分割算法显然是意识流的,它只能割出大概的点云(可能是杯子的一部分,但杯把儿肯定没分割出 ...
- aspose ppt转图片
如果直接转图片,会很模糊采用先将ppt转pdf,在通过pdf转图片,这样出来的结果就非常清晰 var pptFileName = "公司网络及计算机使用与要求.pptx"; Pre ...