题目大意

你开始有一个序列x

它所有项都是0

你有一个操作:x[i]=x[i-1]+1

问你至少几次操作可以让x序列变为给定的a序列

分析

老年人完全不会这种脑子题/kk........

我们定义b[i]=i-a[i]

所以对于一个连续的上升子序列它的b是相等的

每次取一段想的b序列中最大的a[i]累加即可

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
int a[],b[],n,m,ans;
signed main(){
int i,j,k;
scanf("%lld",&n);
for(i=;i<=n;i++){
scanf("%lld",&a[i]);
b[i]=i-a[i];
if(a[i]-a[i-]>||a[i]>=i){
puts("-1");
return ;
}
}
for(i=n;i>;i--){
if(i!=n&&b[i]==b[i+])continue;
ans+=a[i];
}
cout<<ans<<"\n";
return ;
}

AGC024C Sequence Growing Easy的更多相关文章

  1. AtCoder - 3962 Sequence Growing Hard

    Problem Statement Find the number of the possible tuples of sequences (A0,A1,…,AN) that satisfy all ...

  2. [AtCoder Grand Contest 024 Problem E]Sequence Growing Hard

    题目大意:考虑 N +1 个数组 {A0,A1,…,AN}.其中 Ai 的长度是 i,Ai 内的所有数字都在 1 到 K 之间. Ai−1 是 Ai 的子序列,即 Ai 删一个数字可以得到 Ai−1. ...

  3. AGC024E Sequence Growing Hard

    题意 给出\(n\),\(m\),\(mu\),问有多少个序列组\((A_0,A_1,\dots,A_n)\)满足: 序列\(Ai\)的长度恰好为\(i\) 所有元素均在\([1,m]\) \(A_{ ...

  4. Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)

    题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...

  5. 【AtCoder】AGC024

    A - Fairness 如果奇数次是b - a 否则是a - b #include <bits/stdc++.h> #define fi first #define se second ...

  6. HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏

    Coprime Sequence                                                        Time Limit: 2000/1000 MS (Ja ...

  7. Coprime Sequence(前后缀GCD)

    Description Do you know what is called ``Coprime Sequence''? That is a sequence consists of $n$ posi ...

  8. coprime Sequence

    Do you know what is called ``Coprime Sequence''? That is a sequence consists of nn positive integers ...

  9. HDU - 6025 Coprime Sequence(gcd+前缀后缀)

    Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, ...

随机推荐

  1. FormData模拟表单上传图片

    [node]---multer模块实现图片上传---FORMDATA   1.安装muterl第三方模块 cnpm install multer --save 2.使用 multer在解析完成后,会向 ...

  2. python控制流-提前结束进程

    一.sys.exit() 调用 sys.exit()函数,可以让程序终止或退出. 这个函 数在 sys 模块中,必须先导入 sys,才能使用它: #!/usr/bin/env python #codi ...

  3. TCP 和 UDP 的区别---还有一个UTP一

    面试的时候会经常问到这些问题,所以要对比了解一下他们之间的差别,能讲出个所以然来.多积累多总结,懵逼中... TCP 和 UDP TCP与UDP基本区别 : 1.基于连接与无连接 2.TCP要求系统资 ...

  4. STM32 RTC

    目前较为实用的RTC时钟源选择的是:32.768k LSE 低速外部时钟: 不建议实用LSI,精度不高,对时间精度要求不高的可以考虑实用LSI时钟源.数据手册上电气特性的数据:

  5. [2019杭电多校第五场][hdu6630]permutation 2

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6630 题意为求出1-n,n个数的全排列中有多少种方案满足第一位为x,第n位为y,且相邻数字绝对值之差不 ...

  6. HDU 6468 /// DFS

    题目大意: 把 1~15 的数字典序排序后为 1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9 此时给定 n k, 求1~n的数组字典序排序后 第k个 ...

  7. http请求中的Content-Length作用机制与分块chunked

    httpclient-4.5.9.jar org.apache.http: auth     身份 client    端 conn     连接 cookie  本地 impl:    实现 exe ...

  8. 省电的iPhone定位

    1.Getting the User’s Current Location 获取用户当前位置. 获取位置的方式有三种:GPS, cell tower triangulation(蜂窝站点), 和 Wi ...

  9. [POI2006]ORK-Ploughing(贪心,枚举)

    [POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He can begi ...

  10. java并发学习--第三章 线程安全问题

    线程的安全问题一直是我们在开发过程中重要关注的地方,出现线程安全问题的必须满足两个条件:存在着两个或者两个以上的线程:多个线程共享着共同的一个资源, 而且操作资源的代码有多句.接下来我们来根据JDK自 ...